我想通过php从localhost向我的网站发送一封电子邮件到我的Gmail。 我更改了文件 C:\ xampp \ php \ php.ini 和 c:\ xampp \ sendmail \ sendmail.ini。
在php.ini
文件中我添加了extension=php_openssl.dll
和我的
[mail function]
就是这样:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
在另一个文件上,(sendmail.ini)我做了这些更改:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=gmail-id@gmail.com
auth_password=gmail-password
force_sender=gmail-id@gmail.com
我尝试使用端口587,465和25,但我还没有设法发送电子邮件。
我的代码是:
<?php
require "Mail.php";
require "Mail/mime.php";
include('connect.inc');
$email = mysql_real_escape_string( $_POST['forget-email'] );
$sql = "SELECT * FROM database WHERE(email='$email')";
$res = mysqli_query($conn,$sql);
$row = mysqli_fetch_row($res);
$to = $email;
$from = "gmail-id@gmail.com"; // the email address
$subject = "Password Reset";
$host = "smtp.gmail.com";
$port = "587";
$mail->SMTPSecure = "ssl";
$user = "gmail-id@gmail.com";
$pass = "code";
$headers = array("From"=> $from, "To"=>$to, "Subject"=>$subject);
$smtp = @Mail::factory("smtp", array("host"=>$host, "port"=>$port, "auth"=> true, "username"=>$user, "password"=>$pass));
$msg = "You have requested a password change.\n";
if ( $row> 0 ) {
echo "An e-mail has been send to you successfully";
$mail = @$smtp->send($to, $headers, $msg);
if (PEAR::isError($mail)){
echo "error: {$mail->getMessage()}";
} else {
echo "Message sent";
}
}else {
echo "Your e-mail is not on the database. Please register.";
}
?>
当我调用上面的php文件时,我收到此错误:
严格标准:在第18行的C:\ xampp \ htdocs \ check.php中从空值创建默认对象
电子邮件已成功发送给您错误:身份验证失败[SMTP:从服务器收到无效的响应代码(代码:534,响应: 5.7.14请通过网络浏览器和5.7.14登录,然后重试。 5.7.14了解更多信息,请参见5.7.14 https://support.google.com/mail/answer/78754 wx10sm2123259wjb.46 - gsmtp)]
并且没有向我发送电子邮件。 你能帮我吗?