0

I have sent mail using PHPMailer it raising success message but mail wasn't received. Because of it's this beahvior getting very complex to debug.

function mail1($your_name,$from,$subject,$message){
require 'PHPMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Set who the message is to be sent from
$mail->setFrom($from, $your_name);
//Set an alternative reply-to address
$mail->addReplyTo($from, $your_name);
//Set who the message is to be sent to
$mail->addAddress('percept.ashwini@gmail.com', 'Ashvini Lanjewar');
//Set the subject line
$mail->Subject = $subject;//'PHPMailer mail() test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->Body = $message;
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    return "Mailer Error: " . $mail->ErrorInfo;
} else {
    return "Message sent!";
}
}

Note : This mail send code is for contact us page.

Pravin Durugkar
  • 357
  • 3
  • 21
  • 1
    Read [the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). You're using `mail()` to send, so you need to be sure your local mail server is working, check its logs. – Synchro Feb 27 '17 at 09:37

1 Answers1

1

Try this.. easy to get mail with your valuable input

    $to      = "yourname@gmail.com";
    $subject = "Subject of the Mail";

    $message = "<html><body>";
    $message .="Dear ,<br/><br/>";

    $message .= "</body></html>";


    $message .= "Dear ,". "\r\n". "Your comment added sucessfully "."\r\n";


                         $headers  = "MIME-Version: 1.0\r\n";
                         $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                             $headers .= 'From: fromid@gmail.com'."\r\n" .
                                 "Cc:".$sendlist_manager."\r\n" .
                                 'MIME-Version: 1.0'.'\r\n'.
                                 'Content-Type: text/html; charset=\"iso-8859-1\" '."\r\n".
                                  'X-Mailer: PHP/' . phpversion();


if (mail($to, $subject, $message, $headers))
{
    //Send success message.
    echo '<script type="text/javascript">alert("Mail Sent!"); </script>';

}
else
{ 
    echo '<script type="text/javascript">alert(" Mail not sent, please try again!"); </script>';    
}
?>

If you use Mime version and the content type is better I guess..

and if you go detailed about mailer please check here https://github.com/PHPMailer/PHPMailer PHPMailer PHPMailer on Github