Asked  1 Year ago    Answers:  5   Viewed   8 times

I have a problem sending emails with phpmailer .

The code that sends emails is:

$mail_User      = "site@xxxxxxx.com";
$mail_Password  = "My Password";
$mail_address   = "site@xxxxxxx.com";
$mail_Name      = "MyName";
$mail_Server    = "222.222.222.222";
$mail_Port      = 25;

    function SendHTMLMail($to, $cc, $bcc, $subject, $body)
    {
        global $mail_User, $mail_Password, $mail_address, $mail_Name, $mail_Server, $mail_Port;
        $correo = new PHPMailer;
        $correo->SMTPDebug = 3;                               // Enable verbose debug output
        $correo->SetLanguage("es", "/phpmailer/language/");
        $correo->IsSMTP();

        $correo->IsHTML(true);
        $correo->Host = $mail_Server;
        $correo->Port = $mail_Port;
        $correo->SMTPAuth =true;
        //$correo->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $correo->Username = $mail_User;
        $correo->Password = $mail_Password;
        $correo->From      = $mail_address;
        $correo->FromName  = $mail_Name;
        $correo->Subject = $subject;
        $correo->Body    = $body;
        $dest = explode (";", $to);
        for ($n=0; isset($dest[$n]); $n++) $correo->AddAddress($dest[$n]);
        $dest = explode (";", $cc);
        for ($n=0; isset($dest[$n]); $n++) $correo->AddCC($dest[$n]);
        $dest = explode (";", $bcc);
        for ($n=0; isset($dest[$n]); $n++) $correo->AddBCC($dest[$n]);
        if ($correo->Send())
            return "";
        else {
            AddLog("Correo no enviado: $correo->ErrorInfo");
            echo "<br>Correo no enviado: $correo->ErrorInfo<br>";
            return "Correo no enviado: $correo->ErrorInfo";
        }
    }

And the result is :

2016-02-24 04:58:17 Connection: opening to 222.222.222.222:25, timeout=300, options=array (
                                      )
2016-02-24 04:58:17 Connection: opened
2016-02-24 04:58:17 SERVER -> CLIENT: 220-srv1.abcdef.com ESMTP Exim 4.86 #2 Wed, 24 Feb 2016 14:47:17 +0100 
                                      220-We do not authorize the use of this system to transport unsolicited, 
                                      220 and/or bulk e-mail.
2016-02-24 04:58:17 CLIENT -> SERVER: EHLO www.site.com
2016-02-24 04:58:18 SERVER -> CLIENT: 250-srv1.abcdef.com Hello www.doznyk.com [181.181.181.181]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      250 HELP
2016-02-24 04:58:18 CLIENT -> SERVER: STARTTLS
2016-02-24 04:58:18 SERVER -> CLIENT: 220 TLS go ahead
2016-02-24 04:58:18 SMTP Error: Could not connect to SMTP host.
2016-02-24 04:58:18 CLIENT -> SERVER: QUIT
2016-02-24 04:58:19 SERVER -> CLIENT: 221 srv1.abcdef.com closing connection
2016-02-24 04:58:19 Connection: closed
2016-02-24 04:58:19 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Why phpmailer don't send emails? Why it try to use TLS if the code line is a comment?

I replace sensitive data with fake, like server name and IPs. If I change port from 25 to 587 and uncomment the line tls, the result is almost the same.

Thank you


New test, same result.

I read the doc as Synchro suggest me. I changed the port from 25 to 587 and added the line $correo->SMTPAutoTLS = true;

$correo->SMTPAuth =true;
$correo->SMTPAutoTLS = true;
//$correo->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$correo->Username = $mail_User;
$correo->Password = $mail_Password;

The result is:

2016-02-24 06:05:36 Connection: opening to 222.222.222.222:587, timeout=300, options=array (
                                      )
2016-02-24 06:05:37 Connection: opened
2016-02-24 06:05:37 SERVER -> CLIENT: 220-srv1.abcdef.com ESMTP Exim 4.86 #2 Wed, 24 Feb 2016 15:54:37 +0100 
                                      220-We do not authorize the use of this system to transport unsolicited, 
                                      220 and/or bulk e-mail.
2016-02-24 06:05:37 CLIENT -> SERVER: EHLO www.myserver.com
2016-02-24 06:05:38 SERVER -> CLIENT: 250-srv1.abcdef.com Hello www.doznyk.com [181.229.171.247]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      250 HELP
2016-02-24 06:05:38 CLIENT -> SERVER: STARTTLS
2016-02-24 06:05:38 SERVER -> CLIENT: 220 TLS go ahead
2016-02-24 06:05:39 SMTP Error: Could not connect to SMTP host.
2016-02-24 06:05:39 CLIENT -> SERVER: QUIT
2016-02-24 06:05:39 SERVER -> CLIENT: 221 srv1.abcdef.com closing connection
2016-02-24 06:05:39 Connection: closed

 Answers

2

Well. I made a lot of test and cannot see the section of doc that said me Synchro, but Synchro was right.

I added the next code and now works fine!

$correo->SMTPOptions = array(
        'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
); 

Although I do not use SSL, I must clarify that I don't use SSL because phpmailer verifies that SSL is usable. Or must be configured properly

Thanks!

Thursday, April 1, 2021
 
Camsoft
 
4

Based on you code i notice that you are sending an email directly from you web page on your domain.

For example you used an @hotmail.com address.

When the recipient receive the emails the mail service of the recipient may test a reverse DNS of the sender of the mail. So the sender is from @hotmail.com but the mail comes from your domain which of course is not hotmail.com.

So I receive a mail from an address @hotmail.com but the IP sender isn't related at all with domain hotmail.com: that's SPAM!

http://en.wikipedia.org/wiki/Reverse_DNS_lookup

I think a possible solution is: in you PHP code use authenticate with SMTP and from there send the mail!

Thursday, April 1, 2021
 
3

In your code you are sending one message to 1 address and BCCing to all the others, so there is only a single To address - this is just how BCC works. If you want to have each recipient's address shown as the To address, you must send each message individually - look at the mailing list example provided. If you want to spot failures in a long list of recipients of any kind, make sure you're using an up-to-date version of PHPMailer as that was buggy in the past. Any bad addresses will be reported in $mail->ErrorInfo.

Thursday, April 1, 2021
 
tpow
 
5

After trying various ways, i found following code working with almost all email providers

$to['email'] = "recipients email address";      
$to['name'] = "name";   
$subject = "email subject";
$str = "<p>Hello, World</p>";
$mail = new PHPMailer;
$mail->IsSMTP();                                     
$mail->SMTPAuth = true;
$mail->Host = 'Specify main and backup server here';
$mail->Port = 465;
$mail->Username = 'xyz@domainname.com';
$mail->Password = 'email account password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'From Email Address';
$mail->FromName = "Any Name";
$mail->AddReplyTo('xyz@domainname.com', 'any name'); 
$mail->AddAddress($to['email'],$to['name']);
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->WordWrap = 50;    
$mail->IsHTML(true);  
$mail->Subject = $subject;
$mail->Body    = $str;
if(!$mail->Send()) {
$err = 'Message could not be sent.';
$err .= 'Mailer Error: ' . $mail->ErrorInfo;                        
}

$mail->ClearAddresses();

variable values needs to be changed accordingly. Hope these helps people having issues with PHPmailer

Saturday, May 29, 2021
 
Neysor
 
5

try this to show error message

if(!$mail->send()) {
    $msg = "Mailer Error: " . $mail->ErrorInfo;
} else {
    $msg = "Your form has been submitted, thank you. I will reply very soon";
}
Saturday, May 29, 2021
 
Dev
 
Dev
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :