使用Zoho&amp ;;设置邮件服务器为它制作自己的phpMail功能

时间:2015-09-14 09:11:29

标签: php email smtp

我不知道我的代码是否是问题,或者我是否错误地配置了Zoho的SMTP设置。

基本上我希望能够使用简单的php函数动态发送电子邮件,例如

phpMail("to@example.com", $subject, $body, "from@example.com", "replyto@example.com");

这是我的PHPMailer.php脚本(它看到了函数及其设置)

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.zoho.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '**REMOVED**';                 // SMTP username
$mail->Password = '**REMOVED**';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->isHTML(true);                                  // Set email format to HTML


// SYTAX: phpMail($from, $reply, $to, $subject, $body);
function phpMail($to, $subject, $body, $from = "from@example.com", $reply = "replyto@example.com") {
    if (isset($from)) 
        $mail->From = $from;
        $mail->FromName = "testing";

    if (isset($to)) 
        $mail->addAddress($to);

    if (isset($reply)) 
        $mail->addReplyTo($reply);

    if (isset($subject)) 
        $mail->Subject = $subject;

    if (isset($body)) 
        $mail->Body = $body;
        $mail->AltBody = $body;

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }

}

现在问题是,我没有收到电子邮件,也没有收到任何错误/消息,但它也没有给我发电子邮件。

1 个答案:

答案 0 :(得分:0)

以下配置适用于我使用zoho邮件 试一试:

$mail=new JPhpMailer;
$mail->IsSMTP();
$mail->Host='smtp.zoho.com';
// Enable this option to see deep debug info
// $mail->SMTPDebug = 4;  
$mail->SMTPSecure = 'ssl';
$mail->Port='465';
$mail->SMTPAuth=true;

$mail->Username='your_email_address';
$mail->Password='your_eamil_address_password';

$mail->isHTML(true);

$mail->SetFrom('your_email_address','Your Name');

$mail->Subject='PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody='To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');

$mail->AddAddress('destination_email_address','John Doe');

 if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}