在服务器中通过 gmail smtp 发送邮件时出现问题,但在本地主机中工作正常
我在一家免费网络托管公司开设了一个网站,该公司不提供 mail()
功能,因此我决定实现使用 G-mail 的 SMTP 服务器发送电子邮件的功能。
我使用 PEAR 的 Mail 包来发送邮件。它在本地运行良好,但不幸的是它并不全部在我网站的服务器中运行。
打开页面时,即使没有提到错误,也会产生空白屏幕。您可以在此处查看脚本运行情况。
这是我的代码:
<?php
require_once "Mail.php";
$from = "[email protected]";
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "[email protected]";
$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, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
任何人都可以帮助我了解出了什么问题吗?
I have opened a site in a free web hosting company which is not offering mail()
facility so I have decided to implement this facility of sending emails using G-mail's SMTP server.
I have used PEAR' Mail package to send mails. It works fine locally but unfortunately its not all working in my website's server.
When the page is opened, it produces a blank white screen even no errors are being mentioned. You can check here to see the script run.
This is my code:
<?php
require_once "Mail.php";
$from = "[email protected]";
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "[email protected]";
$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, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Can anyone help me to understand what's going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能忘记上传
Mail.php
文件或依赖项之一。白页通常表示致命错误。You maybe forgot to upload the
Mail.php
file or one of the dependencies. A white page often indicates a fatal error.Gmail 阻止了一些网络托管提供商。请与您的网络托管提供商联系。
Gmail blocks some web hosting providers. Contact you your web hosting provider.