dongzi0602 2018-08-11 08:50
浏览 34

PHPMailer无法在Namecheap服务器中运行

I have written the following code to send email from my website hosted in Namecheap.

<?php
include("constants.php");

require_once('libs/phpmailer/class.phpmailer.php');
require_once("libs/phpmailer/class.smtp.php");
require ("libs/phpmailer/PHPMailerAutoload.php");

try {
    $mailer = new PHPMailer();
    $mailer->IsSMTP();
    $mailer->SMTPSecure = 'tls';
    $mailer->Host = 'smtp.zoho.com';
    $mailer->SMPTDebug = 2;
    $mailer->Port = 587;
    $mailer->Username = EMAIL;
    $mailer->Password = PASSWORD;
    $mailer->SMTPAuth = true;
    $mailer->From = EMAIL;
    $mailer->FromName = "User";
    $mailer->Subject = 'New Query Received';
    $mailer->isHTML(true);
    $mailer->Body = '<p>Hello,</p><p> The following query was received from '.$_POST['name']. '.<br>"'. $_POST['message']. '"</p><p>'.'His email is '.$_POST['email'].'</p><p>Hope you will have a great day.</p><p>Best Regards,</p>';
    $mailer->AddReplyTo(EMAIL_REC, 'Contact');

    $mailer->AddAddress(ADDRESS, NAME);

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


    if ($mailer->Send()) {
        echo "Sent";
    } 
    else {
        echo $mailer->ErrorInfo;     
    }
}
catch (phpmailerException $e) {
    echo $e->errorMessage(); 
} catch (Exception $e) {
    echo $e->getMessage(); 
}

header('Location:index.html');
exit;

?>

I am using zoho mail for my email host but I have tried the same using a gmail account too. I have already cross verified the EMAIL and its password.

The code works perfectly fine in my localhost but causes "SMTP connect() failed" in the Namecheap server.

If I comment $mailer->IsSMTP(); then no error is shone but email is not sent.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒