[英]PHP send email PEAR fail
Send email using the GMail SMTP server from a PHP page 使用GMail SMTP服务器从PHP页面发送电子邮件
I'm trying to get this to work. 我正在尝试使它起作用。 According to the answer in the given link "it's working code so use it".
根据给定链接中的答案,“它是有效的代码,请使用它”。 Except it doesn't work for me.
除非它对我不起作用。
In particular: 尤其是:
<?php
require_once "Mail.php";
$from = "<xxxxx.gmail.com>";
$to = "<xxxxx.gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.gmail.com";
$port = "465";
$username = "xxxxx@gmail.com";
$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>");
}
?> <!-- end of php tag-->
Produces: 产生:
Strict Standards: Non-static method Mail::factory() should not be called statically in F:\\xampp\\htdocs\\test\\index.php on line 23
严格标准:非静态方法Mail :: factory()不应在23行的F:\\ xampp \\ htdocs \\ test \\ index.php中静态调用
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in F:\\xampp\\php\\PEAR\\Mail\\smtp.php on line 365
严格标准:非静态方法PEAR :: isError()不应被静态调用,假设$ this来自365行的F:\\ xampp \\ php \\ PEAR \\ Mail \\ smtp.php中不兼容的上下文
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in F:\\xampp\\php\\PEAR\\Net\\SMTP.php on line 450
严格的标准:非静态方法PEAR :: isError()不应被静态调用,假设$ this来自第450行的F:\\ xampp \\ php \\ PEAR \\ Net \\ SMTP.php中不兼容的上下文
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in F:\\xampp\\php\\PEAR\\Net\\SMTP.php on line 467
严格标准:非静态方法PEAR :: isError()不应静态调用,假定第467行的F:\\ xampp \\ php \\ PEAR \\ Net \\ SMTP.php中的不兼容上下文中的$ this
While phpinfo() gives registered sockets: 虽然phpinfo()提供了注册的套接字:
tcp, udp, ssl, sslv3, sslv2, tls
tcp,udp,ssl,sslv3,sslv2,tls
But most importantly, no email sent. 但最重要的是,没有发送电子邮件。
Try setting correct email addresses in $from
and $to
尝试在
$from
和$to
设置正确的电子邮件地址
'PeterMorgan@gmail.com' instead of '<PeterMorgan.gmail.com>'
From PEAR Mail documentation: 从PEAR Mail文档中:
include('Mail.php');
$recipients = 'joe@example.com';
$headers['From'] = 'richard@example.com';
$headers['To'] = 'joe@example.com';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params = ... // set smtp values here
// http://pear.php.net/manual/en/package.mail.mail.factory.php
$mail_object =& Mail::factory('smtp', $params);
$mail_object->send($recipients, $headers, $body);
Figured out the issue. 找出问题。 For GMail they say on their website:
对于GMail,他们在其网站上说:
Port for TLS/STARTTLS: 587
TLS / STARTTLS的端口:587
Port for SSL: 465
SSL连接埠:465
If you're having trouble sending mail but you've confirmed that encryption is active for SMTP in your mail client, try to configure your SMTP server on a different port (465 or 587).
如果您在发送邮件时遇到麻烦,但已确认邮件客户端中的SMTP加密处于活动状态,请尝试在其他端口(465或587)上配置SMTP服务器。
So I changed the port from 465 to 587, even though I am using SSL. 因此,即使我使用SSL,我也将端口从465更改为587。 I don't know why this works for me but it does.
我不知道为什么这对我有用,但确实如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.