简体   繁体   中英

Trying to send mail using yahoo smtp in php

Please can some one suggest me codes to send mails using yahoo smatp, and php..

require("class.phpmailer.php"); // be sure to change this to your location!

$mail = new PHPMailer();    
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier    

$mail->Host = "smtp.mail.yahoo.com"; // sets yahoo as the SMTP server    
$mail->Port = 25; // set the SMTP port    
$mail->Username = "sumthing@yahoo.com"; // yahoo username    
$mail->Password = "password"; // yahoo password

$mail->From = "sumthing@yahoo.com";
$mail->FromName = "myname";    
$mail->AddAddress("you@example.com");    
$mail->Subject = "Test PHPMailer Message";    
$mail->Body = "Hi! \n\n This was sent with phpMailer_example3.php.";

if(!$mail->Send()) {

    echo 'Message was not sent.';    
    echo 'Mailer error: ' . $mail->ErrorInfo;

} else {

    echo 'Message has been sent.';

}

This code is giving me errrors 'Could not connect to SMTP host".

Many of the sites providing SMTP do not support SSL (SMTP-S). If supported is usually in different port, such as 465. Connecting to 465 often fails. Try commenting out

$mail->SMTPSecure = "ssl"

Try also first without authentication to make sure the connection works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM