doulingzhuang3079 2015-10-23 15:26
浏览 66

使用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;
}
  • 写回答

1条回答

  • duandange7480 2016-02-29 06:44
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键