繁体   English   中英

使用SMTP PHPMailer作为“域”电子邮件地址,已发送但未收到电子邮件

[英]Using SMTP PHPMailer for 'Domain' email address, email sent but not recieved

我正在使用PHPMailer发送电子邮件。 当我使用gmail smtp时,它工作正常,但是当我尝试使用域smtp时,我在屏幕上看到的是“邮件已发送! 但我完全没有收到任何电子邮件。 我试过使用调试器,它说

We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 

这是我的代码

<?php
date_default_timezone_set('Etc/UTC');
//Load PHPMailer dependencies
require_once 'PHPMailerAutoload.php';
require_once 'class.phpmailer.php';
require_once 'class.smtp.php';

/* CONFIGURATION */
$crendentials = array(
    'email'     => 'xxxxx@example.com',    
    'password'  => 'xxxxxx'               
    );

$smtp = array(

'host' => 'secure.ehostpk.com',
'port' => 465,
'username' => $crendentials['email'],
'password' => $crendentials['password'],
'secure' => 'ssl' //SSL or TLS

);

/* TO, SUBJECT, CONTENT */
$to         = 'xxxxxx@example.com'; //The 'To' field
$subject    = 'This is a test email sent with PHPMailer';
$content    = 'This is the HTML message body <b>in bold!</b>';



$mailer = new PHPMailer();

//SMTP Configuration
$mailer->isSMTP();
$mailer->SMTPDebug  = 2;
$mailer->SMTPAuth   = true; //We need to authenticate
$mailer->Host       = $smtp['host'];
$mailer->Port       = $smtp['port'];
$mailer->Username   = $smtp['username'];
$mailer->Password   = $smtp['password'];
$mailer->SMTPSecure = $smtp['secure']; 

//Now, send mail :
//From - To :
$mailer->From       = $crendentials['email'];
$mailer->FromName   = 'Team'; //Optional
$mailer->addAddress($to);  // Add a recipient

//Subject - Body :
$mailer->Subject        = $subject;
$mailer->Body           = $content;
$mailer->isHTML(true); //Mail body contains HTML tags

//Check if mail is sent :
if(!$mailer->send()) {
    echo 'Error sending mail : ' . $mailer->ErrorInfo;
} else {
    echo 'Message sent !';
}

我搜索了很多东西,但我不知道该怎么办。 任何帮助将不胜感激。

我发现的一件事是,这些天在大多数服务器(尤其是cpanel服务器)上,实际上要在cpanel自身中创建要尝试发送的电子邮件地址,以使其正常工作。

据我了解,脚本仅将其路由到服务器和电子邮件帐户,然后再从那里路由,最后从服务器上的电子邮件帐户发送出去。 因此,解决方案可能是在服务器中实际设置电子邮件地址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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