2015-11-10 2 views
0

Я пытаюсь отправить почту, используя функцию php mail. но я получаю сообщение об ошибке, как:Функция php mail не работает Ответ SMTP-сервера: 503

PHP Warning: mail(): SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server. in C:\Inetpub\vhosts\qubedns.co.in\httpdocs\Codes\design\rnp\mailsend.php on line 21 

Вот мой PHP SCRIPT:

<?php 

$toEmail = '[email protected]'; 
$subject = 'hello'; 
$message = 'Users are able to send emails to local domains and addresses but are unable to send email to any external address.'; 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n"; 

$Status = mail($toEmail,$subject,$message,$headers); 

if($Status){ 
    echo '1'; 
}else{ 
    echo '0'; 
} 

?> 

Вот моя конфигурация сервера: http://qubedns.co.in/codes/php/

Что случилось со мной?

+0

настроить SMTP с электронной почты и пароль, если вы не используете локальный адрес электронной почты – Prafulla

+0

Не помечать вопрос с PHPMailer, если вы не используете [PHPMailer] (HTTPS://github.com/PHPMailer/PHPMailer), но если вы не знаете, что делаете с 'mail()', вы должны быть! – Synchro

ответ

0

Я нашел решение с PHPMailer. Его работа для меня.

<?php 
require('mailserver/PHPMailerAutoload.php'); 
require('mailserver/class.phpmailer.php'); 
require('mailserver/class.smtp.php'); 
require('mailserver/class.pop3.php'); 

$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->CharSet="UTF-8"; 
$mail->Debugoutput = 'html'; 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 465; 
$mail->SMTPSecure = 'ssl'; 
$mail->SMTPAuth = true; 
$mail->IsHTML(true); 
$mail->Username = '[email protected]'; 
$mail->Password = 'password'; 
$mail->From = '[email protected]'; 
$mail->FromName = 'Leon Sales Team'; 
$mail->AddAddress($to); 
$mail->AddReplyTo('[email protected]', 'Leon Sales Team'); 
$mail->Subject = $sub; 
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; 
$mail->Body = $message; 
if(!$mail->Send()){ 
    echo "1"; // ERROR 
}else{ 
    echo "0"; // SUCCESS 
} 
?>