2017-12-27 161 views
1

代码:无法使用PHP中使用GoDaddy的电子邮件凭证发送邮件

<?php 
    try { 
     require_once "Mail.php"; 
     require_once "Mail/mime.php"; 
     $from = "[email protected]"; 
     $to = "[email protected]"; 
     $subject = "Testing email please ignore"; 
     $message = "Just testing"; 
     $host = "godaddyhost"; 
     $port = "465"; 
     $username = "[email protected]"; 
     $password = "password"; 
     $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); 
     $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); 
     $mail = $smtp->send($to, $headers, $message); 
     if (PEAR::isError($mail)) { 
       echo("<p>" . $mail->getMessage() . "</p>"); 
     } else { 
       echo("<p>Message successfully sent!</p>"); 
     } 

    } catch(Exception $e) { 
     echo $e; 
    } 
    ?> 

我现在面临上执行上述script

This page isn’t working 
localhost is currently unable to handle this request. 
HTTP ERROR 500 

在浏览器中的一个问题。如果我的评论我的代码从$mail = $smtp->send($to, $headers, $message);,只是简单echo "something";然后我可以看到我的浏览器上的东西

日志

[Wed Dec 27 17:07:36.033665 2017] [:error] [pid 28115] [client ::1:41546] PHP Warning: include_once(Net/SMTP.php): failed to open stream: No such file or directory in /usr/share/php/Mail/smtp.php on line 365 
[Wed Dec 27 17:07:36.033715 2017] [:error] [pid 28115] [client ::1:41546] PHP Warning: include_once(): Failed opening 'Net/SMTP.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/php/Mail/smtp.php on line 365 
[Wed Dec 27 17:07:36.033741 2017] [:error] [pid 28115] [client ::1:41546] PHP Fatal error: Class 'Net_SMTP' not found in /usr/share/php/Mail/smtp.php on line 366 
+0

好像你还没有在服务器上安装SMTP。 – panther

+0

我正在尝试从本地主机 –

+1

这是无关紧要的。所以你没有在你的本地服务器上安装SMTP。 – panther

回答

1

请安装“Net /”类。

使用此命令在Linux机器上,sudo pear install Net_SMTP

pear install Net_SMTP的Windows机器。 OR

下载以下,并把它们放在/净

http://pear.php.net/package/Net_SMTP/download

http://pear.php.net/package/Net_Socket/download

+0

我现在面临这个异常 无法连接到smtpout.asia.secureserver.net:465 [SMTP:从服务器收到无效的响应代码(代码:-1,回应:)] –

+0

请参阅此答案https://stackoverflow.com/questions/21841834/phpmailer-godaddy-server-smtp-connection-refused – Archish

相关问题