這裏是從本地主機發送電子郵件的代碼,因爲我從網上引用了很多。郵件錯誤:SMTP連接()在PHP郵件程序中失敗(https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting)
HTML表單:
<form method="post" action="email.php">
Email: <input name="email" id="email" type="text" /><br />
Message:<br />
<textarea name="message" id="message" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
email.php:
<?php
// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';
$mail = new PHPMailer();
$body='hellooooo';
$mail->IsSMTP();
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "zzz"; // SMTP password
$mailer->SMTPSecure = 'ssl';
$mailer->Port = 465;//587;
$mail->AddAddress("xxx", "xx");
$mail->SetFrom('[email protected]','xxxx');
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->MsgHTML($body);
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
所以,當我運行我的代碼,它顯示了這樣的錯誤,
Message could not be sent.
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
而且我在這個刪除分號從以下文件中選擇;extension=php_openssl.dll
,然後重新啓動xampp。
c/xampp/apache/bin/php.ini and c/xampp/php/php.ini
仍然停留同樣的錯誤..
注:我新來的PHP,但我想知道具體的這一個,解決問題。我提到了類似的問題,但它並沒有幫助我,
任何人都可以幫我解決這個問題嗎?
謝謝,
感謝您的編輯,我忘了刪除密碼.. – pcs
永遠不要暴露您的用戶名和密碼!它需要第二個劫持你的帳戶伴侶。 –
@Maverick:我已經做了,你上面的鏈接解釋了什麼..仍然我有同樣的錯誤.. – pcs