Я пытаюсь использовать phpmailer для отправки писем. Теперь он отлично работал с моим локальным хостом, но как только я загрузил его на свой сайт, он никогда не работал? Может ли кто-нибудь сказать мне, как заставить его работать, или где я могу найти решение? Я попробовал погулять, но это мало помогло.Как отправить почту с сервера с помощью php?
код с локальным хостом -
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('PHPMailer_5.2.4/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body=$_POST["purpose"]." mailed to you by - ".$_POST["name"]." (".$_POST["number"].",".$_POST["email"].")";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "gmail_username"; // GMAIL username
$mail->Password = "gmail_password"; // GMAIL password
$mail->SetFrom($_POST["email"], 'First Last');
$mail->AddReplyTo("[email protected]","First Last");
$mail->Subject = $_POST["subject"];
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
header('Location: http://www.facebook.html') ;
} else {
header('Location:http://www.google.com') ;
}
?>
для моего сервера я сделал следующие изменения -
<?php
$mail->Host = "mail.exoticalstudio.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "password_for_webmail"; // GMAIL password
if(!$mail->Send()) {
header('Location: http://www.facebook.html') ;
} else {
header('Location:http://www.google.com') ;
}
?>
Я пробовал использовать информацию об ошибке, не используя форму и непосредственно запустив скрипт, где я получаю ошибку отказа авторизации. Как я могу это решить?
SMTP -> FROM SERVER:220 mx.google.com ESMTP oo13sm84286802oeb.0 - gsmtp
SMTP -> FROM SERVER: 250-mx.google.com at your service, [50.22.12.14] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250 CHUNKING
SMTP -> ERROR: Password not accepted from server: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at https://support.google.com/mail/bin/answer.py?answer=787 534 5.7.14 54 oo13sm84286802oeb.0 - gsmtp
SMTP -> FROM SERVER:250 2.1.5 Flushed oo13sm84286802oeb.0 - gsmtp
SMTP -> FROM SERVER:530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
SMTP -> ERROR: MAIL not accepted from server: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
The following From address failed: [email protected] : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
The following From address failed: [email protected] : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
The following From address failed: [email protected] : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 oo13sm84286802oeb.0 - gsmtp
Обнаружено подозрительное действие входа в систему, как сделать доверенную деятельность, пожалуйста, помогите.
(1) Что вы имеете в виду под «не работает»? Вы получаете ошибки? Сбои? Почта просто не отправляется? (2) Вы проверяли журналы ошибок? –
'$ mail-> Host =" smtp.gmail.com; 'кажется, что здесь отсутствуют котировки закрытия. – Peon
Я разместил эти цитаты там, пропустил их здесь во время комментирования, и то, что я имею в виду, не работает - я не переадресовываться на facebook или google, поэтому я не знаю, была ли отправлена почта или нет. Я проверил журналы ошибок, ошибки php не отображаются, но в моем письме я не получал никакой почты или нет почты в моей отправленной почте. – DeadMan