I am trying to send email in php using SMTP
. But don't know why it is not returning anything.
It is working fine without SMTP
.
Do I need to add any extra or anything on Hosting Server
?
My Code:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = "example@gmail.com";
$mail->Password = "password";
$mail->SetFrom($email);
$mail->Subject = $subject;
$mail->Body = $mail_body;
$mail->AddAddress("info@neelcomputech.com");
if(!$mail->Send())
{
alert('Mailer Error: ' . $mail->ErrorInfo);
}
else
{
alert('Success');
}
please try this u will be getting the solution
http://webnaar.wordpress.com/2014/03/17/smtp-mailler-for-php/
You need to download the zip file from this repositry : PHPMailer Then you need to extract the PHPMailerAutoload.php
, class.phpmailer.php
and class.smtp.php
files into your directory of the script. Also add require 'PHPMailerAutoload.php';
to the top of your PHP file. The repositry under the PHPMailer has a good explanation of how to get it running under Installation & loading.
Also note what aspin said in the comments that you shouldn't be using alert(); use echo instead.
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Success";
}
Try this code - -
include("class.phpmailer.php");
// You can download class.phpmailer.php from
// https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = "myid@gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom('myid@gmail.com');
$mail->Subject = 'Test EM';
$mail->Body = 'Hi!';
$mail->AddAddress("myid@gmail.com");
if(!$mail->Send()) {
print('Mailer Error: ' . $mail->ErrorInfo);
} else {
print('Success');
}
Let me know if still you face any issue.