簡體   English   中英

需要幫助,使用Gmail SMTP在PHP中發送電子郵件

[英]Need help sending email in PHP using Gmail SMTP

因此,我嘗試按照此處的說明進行操作

http://www.9lessons.info/2011/07/send-mail-using-smtp-and-php.html

使用PHP使用我的gmail帳戶發送電子郵件。 但是,當我嘗試發送測試電子郵件時,我在Web瀏覽器中收到以下消息:錯誤:無法連接到主機“ smtp.gmail.com”

這是我的兩個文件(編輯了我的個人數據)

謝謝你的幫助

<?php
print "1";
require("smtp.php");
require("sasl.php"); //SASL authentication
$from="support@yourwebsite.com"; 
$smtp=new smtp_class;
$smtp->host_name="smtp.gmail.com"; // Or IP address
$smtp->host_port=465;
$smtp->ssl=0;
$smtp->start_tls=1;
$smtp->localhost="localhost";
$smtp->direct_delivery=0;
$smtp->timeout=10;
$smtp->data_timeout=0;
$smtp->debug=1;
$smtp->html_debug=1;
$smtp->pop3_auth_host="";
$smtp->user="john@gmail.com"; // SMTP Username
$smtp->realm="";
$smtp->password="House22"; // SMTP Password
$smtp->workstation="";
$smtp->authentication_mechanism="";
print "3";
if($smtp->SendMessage(
$from,
array(
$to
),
array(
"From: $from",
"To: $to",
"Subject: $subject",
"Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
),
"$message"))
{
print "Message sent to $to OK."; 
}
else
print "Cound not seend the message to $to.\nError: ".$smtp->error;
print "4";
?>

==============================

<?php
$to="ralph@website.com";
$fn="First Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="test@grove.net";
$subject = "Welcome to Website";
$message = "Dear $name, 
Your Welcome Message.
Thanks
www.website.com
";
include('smtpwork.php');
?>

根據Gmail政策,您不能使用plain password (house22) ,而必須使用encrypted password(Gh45515HGGujKkkHk5554) ,因為需要在Gmail帳戶上啟用兩種身份驗證。 之后,創建“應用程序專用密碼”,然后將該密碼用於SMTP,希望對您有用。 這是link1 Link2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM