使用PhpMailer,但永远不会从class.smtp.php中的get_lines()返回

I've been trying to get my PhpMailer to work for over a week now.

I'm on a Windows machines, so I set up a "droplet" server with DigitalOcean (because they seem to have good step-by-step instructions) and then set up fake email accounts with ZohoMail (because it's free and I just need to test this.)

I've got breaks all over the three PhpMailer files I need (PhpMailerAutoload.php, class.phpmailer.php, and class.smtp.php). What I figured out is that I'm getting hung up on this line:

class.smtp.php  line 1060 (or about since I've got breaks in there)
inside function get_lines:
    $str = @fgets($this->smtp_conn, 515); 

I put in more breaks, as below:

//*********Debug Code here
$test = $this->smtp_conn;
echo "
Contents of test var: 
";
var_dump($test);

echo "about to set str var 
";
$str = @fgets($test, 515);
echo "Contents of str var 
";
var_dump($str);

echo "
 out of debug code";
//***********End of debug code

After two minutes (2 minutes and 5 seconds to be precise) $test var_dumps just fine and "about to set str var" prints just fine. But that's it. No more code executes.

I don't know what @fgets is. I don't see any documentation in the PHP manual for that, so I'm not sure where to go from here.

FIRST IDEA: I checked on my php versions:
- server is running 5.5.9 - my PC is running 5.6.12 I'm guessing those are close enough.

SECOND IDEA: I found that in the past there are a "==" vs "=" issue with this line of code, but that's clearly not the issue here.

THIRD IDEA: I also read that some people fixed this problem by making sure that "php_openssl.dll" is enabled in their php.ini file.

In mine I have a line that reads: extension = php_openssl.dll So I think that's OK.

FOURTH IDEA: Is my configuration wrong? I'm using the following: SMTP Host: smtp.zoho.com (should I get the IP address instead?) SMTP Port: 465 and I think I have encryption and authentication turned on. (My code is at the end if that helps.)

FIFTH IDEA: Start over using gmail to see if that gives me any clues, unless someone has a better idea.

function send_SMTP_email($email, $name, $subject, $msg) {

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require_once '/inc/phpmailer/PHPMailerAutoload.php';  // will load class.phpmailer.php and class.smtp.php itself
require_once '/inc/config.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging, TO DO:  Disable for production
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = SMTP_HOST;
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = SMTP_PORT;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication
$mail->Username = SYSTEM_EMAIL;
//Password to use for SMTP authentication
$mail->Password = SYSTEM_PASSWORD;

//Set who the message is to be sent from
$mail->setFrom(SYSTEM_EMAIL, SYSTEM_NAME);
//Set an alternative reply-to address
$mail->addReplyTo(SYSTEM_EMAIL, SYSTEM_NAME);
//Set who the message is to be sent to
$mail->addAddress($email, $name);

//Set the subject line
$mail->Subject = $subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

//Send HTML OR Plain Text
$mail->isHTML(true);
//Set body
$mail->Body = "<p>" . $msg . "</p>";
//Include plain text if non-HTML email reader
$mail->AltBody = $msg;

//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
$result = $mail->send();
//send the message, check for errors
//if (!$mail->send()) {
if (!$result) {
    $return_val = "Mailer Error: " . $mail->ErrorInfo;
} else {
    $return_val = "";
}

return $return_val;
}
php
dousui7410
dousui7410 谢谢你的建议。我以后要试试。我只是不能再面对那个代码了。我想我会做一些文档然后再回过头来。但是你的方式发送好的共鸣。
大约 5 年之前 回复
douzhuo1853
douzhuo1853 要调试低级别问题,请尝试设置SMTPDebug=4.让它等待输入表示服务器出现问题,标准超时很长(5分钟)。
大约 5 年之前 回复
douyunhuan9886
douyunhuan9886 更新:在45分钟内,我能够让gmail的工作正常。(我说过我已经在这一周了吗?有时我想扔东西。)显然,外部服务器正在发生这种情况。最终我想在专业服务器上安装我的应用程序,所以我应该继续考虑这个问题吗?还是浪费时间,因为当我将所有代码移到生产服务器时,我将不得不再次完成整个过程?
大约 5 年之前 回复

1个回答

I just had the same problem and finally found the problem. The default is set to TLS. Once I changed it to SSL with

$mail->SMTPSecure = 'ssl';

everything worked fine. Hopes this helps, if anyone else faces the same issue.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐