0

I am being troubled from the send mail function using phpmailer running at localhost.

I use XAMPP, phpmailer

The $mail->IsSMTP() or $mail->IsSendmail() is working well on the hosting, but not localhost.

I had tried many solution mentioned on the internet, such as enabled the OPENSSL (extension=php_openssl.dll)

For using $mail->IsSendmail() of phpmailer, it shown "Could not execute: /usr/sbin/sendmail".

For using $mail->IsSMTP() with well configured, all are setting correctly.

It shows

 "SMTP Error: Could not authenticate.", 

I had the info from its debugger, there is info "...SMTP -> ERROR: Password not accepted from server:..."

But those had no problem on the live hosting environment, just only not work at localhost.

Hope someone can give me some idea. Many Thanks.

Thiyagu
  • 17,362
  • 5
  • 42
  • 79
Kenshin
  • 11
  • 1
  • 1

2 Answers2

1

isSendmail is unlikely to work on Windows - use isMail if you have a local mail server installed, and if you do, make sure it's up and running (e.g. telnet localhost 25). isSMTP sends directly and is unaffected by local mail config, which is why it's working for you. You should also read the troubleshooting docs.

Synchro
  • 35,538
  • 15
  • 81
  • 104
-2

Download & INSTALL PHPMailer

https://github.com/PHPMailer/PHPMailer Extract class.phpmailer.php and class.smtp.php uncomment ;extension=php_openssl.dll in php.ini normaly located under xampp/php/ folder find [mail function] and change (for Microsoft)

SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = yrmailaddress@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Edit class.smtp.php, host and port parameters like (for Linux): $host="ssl://smtp.gmail.com" $port=465

[edit delete sendmail params]

Example code for sending mail:

   <?php
require_once "phpmailer/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourusername@gmail.com"; // Enter your SMTP username
$mail->Password = "yourpassword“; // SMTP password
$webmaster_email = "yourusername@yourdoamin.com"; //Add reply-to email address
$email="yourusername@domain.com"; // Add recipients email address
$name="name"; // Add Your Recipient’s name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = <strong>50</strong>; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML

$mail->Subject = "This is your subject";

$mail->Body =      "Hi, this is your email body, etc, etc" ;      //HTML Body

$mail->AltBody = "Hi, this is your email body, etc, etc";     //Plain Text Body
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
Rob
  • 45,296
  • 24
  • 122
  • 150
  • Lots of bad advice here I'm afraid. PHPMailer has not been maintained on google code for a long time - [get it from github](https://github.com/PHPMailer/PHPMailer). The (obsolete) example code has been corrupted with culy quotes. The gmail settings are not correct. sendmail.ini settings are irrelevant because you're using direct SMTP. – Synchro Feb 01 '15 at 09:06
  • I answered too quickly, I had not corrected the parameters googles or quotes in the code and I forgot a paragraph on sendmail I finally removed because I agree it's not really useful . to want to go too fast I forget to correct my mistakes, sorry --". – Grégory Salmon Feb 01 '15 at 09:33