在獲得正確的梨位置後,我的代碼不會產生任何錯誤。 但它不會發送電子郵件。電子郵件正文是從首先將數據輸入到mysql數據庫中的表單生成的,然後將相同的數據通過電子郵件發送給使用該數據的人。我已經在這個論壇和其他(這是最好的)論壇上讀過大量的問題和答案,我寫的大部分代碼都受到這個論壇的啓發。 Gmail帳戶有效,密碼正確。任何幫助或建議將非常感激。PHP使用PEAR通過Gmail發送電子郵件smtp
梨,梨郵件安裝在服務器上,似乎是工作(至少不會產生任何錯誤) 這裏是我的代碼:
//Email process code
ini_set('display_errors','on');
error_reporting(E_ALL);
/*
require_once 'System.php';
if(class_exists('System')===true) {
echo 'PEAR is installed!';
} else {
echo 'PEAR is not installed :(';
}
*/
set_include_path('/home/surfcup/php/');
require_once "Mail.php";
$from = "<[email protected]>";
$ToEmail = "<[email protected]>";
$EmailSubject = 'Hotel Registration Form';
$host ="ssl://smtp.gmail.com";
$port ="465";
$username = "[email protected]";
$password = "password";
$headers = array ('From' => $from, 'To'=> $ToEmail, 'Subject'=> $EmailSubject);
$smtp = Mail::factory('smtp',
array ('host'=> $host,
'port'=> $port,
'auth'=> true,
'username'=> $username,
'password'=> $password));
$MESSAGE_BODY = "Event: ".$Event."\n";
$MESSAGE_BODY .= "Name: ".$realname."\n";
$MESSAGE_BODY .= "Age Group: ".$Age."\n";
$MESSAGE_BODY .= "Sex: ".$Sex."\n";
$MESSAGE_BODY .= "Contact Name: ".$Contact_Name."\n";
$MESSAGE_BODY .= "Contact Email: ".$Contact_Email."\n";
$MESSAGE_BODY .= "Phone: ".$Phone."\n";
$MESSAGE_BODY .= "Hotel Name: ".$Hotel_Name."\n";
$MESSAGE_BODY .= "No Rooms: ".$No_Rooms."\n";
$MESSAGE_BODY .= "Rate: ".$Rate."\n";
$MESSAGE_BODY .= "Check In Date: ".$Check_In."\n";
$MESSAGE_BODY .= "Check Out Date: ".$Check_Out."\n";
$MESSAGE_BODY .= "Additional Info: ".$Add_Info."\n";
$mail = $smtp->send($ToEmail, $headers, $MESSAGE_BODY);
if (PEAR::isError($mail)){
echo("<p>" . $mail->getMessage . "</p>");
echo("\n");
echo("<p>" . $mail->getDebugInfo . "</p>");
}
對不起,我不明白 – user316717
我回去,並接受了答案,那幫助了我。對不起,感謝您指出了我。 – user316717