Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPmailer class returns true but email is not delivered

Tags:

php

phpmailer

I am trying to send an email in following way -

from : [email protected]  
reply-to : [email protected]  
to : [email protected]  
cc : [email protected]  

My email is getting delivered to the address mentioned in CC (If I replace the emails to and cc, then email is sent to the address mentioned in to)

For some reason, email is not getting delivered to the address [email protected]. If I send the email manually to this address using outlook or gmail, then email is actually delivered. How can I debug this issue ?

I checked spam/junk directories as well, no emails over there. I tried using php mail() function as well as phpmailer class. Both of them return TRUE. What could the reason ? Please help.

$mail->From = "[email protected]";   
$mail->AddReplyTo("[email protected]");  
$mail->AddAddress("[email protected]");  
$mail->AddCC("[email protected]");  
$mail->Subject = $subject;  
$mail->Body = $message;  

if(! $mail->Send()) {  
    echo "Message was not sent";  
    echo "Mailer Error: " . $mail->ErrorInfo;  
    exit; 
} 
like image 706
Aniruddha Shival Avatar asked Nov 07 '12 11:11

Aniruddha Shival


1 Answers

Try to set cofigurations beffore send (Gmail config):



    $mail = new Mailer();
    $mail->SMTPDebug = true;
    $mail->SMTPAuth = true;
    $mail->CharSet = 'utf-8';
    $mail->SMTPSecure = 'ssl';
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = '465';
    $mail->Username = 'your login here';
    $mail->Password = 'your password here';
    $mail->Mailer = 'smtp';
    $mail->From = 'form mail address';
    $mail->FromName = 'from name';
    $mail->Sender = 'form mail';
    $mail->Priority = 3;

    $mail->AddAddress('mail', 'admin name');
    $mail->AddReplyTo('replay to', 'admin name');
    $mail->Subject = 'subject';
    $mail->Body = 'some HTML message here';
    $mail->IsHTML(true);
    if(!$this->Send()) {
        print_r('error: '. $mail->ErrorInfo); // Show errors   
 }
    $mail->ClearAddresses();
    $mail->ClearAttachments();
like image 164
RDK Avatar answered Oct 25 '22 07:10

RDK