• Page:
  • 1

send mail through php script on localhost

OFFLINE

send mail through php script on localhost

3 years ago
Hiii All,
I wanted to send mail through PHP script. It was not happening from localhost. But Today finally I found a code using that we can send e-mail with our 'gmail' account through PHP script from localhost. Below code is working well in 'joomla'. The code is-

<?php
$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                       // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'yourname@gmail.com';               // SMTP username
$mail->Password = 'yourpassword';                     // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 587;
                                                      //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('yourid@gmail.com', 'Yourname');       //Set who the message is to be sent from

//$mail->addReplyTo('labnol@gmail.com', 'First Last');//Set an alternative reply-to address

$mail->addAddress('to@gmail.com', 'yourname');        // Add a recipient

//$mail->addAddress('ellen@example.com');             // Name is optional
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the message body in bold!';
if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}
echo 'Message has been sent';
?>


Thanks
Last Edit: 3 years ago by Vicky Jain.
OFFLINE

Re: send mail through php script on localhost

3 years ago


In case of Joomla websites, you have this in the global configuration page too under Email settings, just configure there and you will be able to send emails from localhost through gmail

Alternatively, you can also set these in your php.ini file so that whenever you call mail() function, it will automatically pickup the settings from php.ini and send the email through gmail. Refer this link for more information:

stackoverflow.com/questions/600725/how-t...nd-email-using-gmail
OFFLINE

Error in sending mail through php script using gmail account

2 years, 10 months ago
Hi All,

I was trying to send mail using php code with gmail account credentials. I was getting error mentioned in screenshot-


error_2015-11-17.png


For overcome this problem goto below mentioned link when you are login in your gmail account-

www.google.com/settings/security/lesssecureapps

And turn on the access for less secure apps


solution.png


Now you can send mail through your gmail credentials with php script.

Thanks
The following user(s) said Thank You: Farhan Sahibole, Pawan Priyadarshi
  • Page:
  • 1

Upcoming Events

Who's Online

2 users online