2016-04-21 10 views
-2

meine PHP-Mailer fein auf localhost funktioniert, aber wenn ich auf cPanel gleichen Code bin ich laufen Fehlermeldung m bekommen: SMTP connect() fehlgeschlagenPHP-Mailer funktioniert nicht auf cPanel

<?php 
require 'PHPMailer/PHPMailerAutoload.php'; 
$mail = new PHPMailer; 
$mail->isSMTP();          
$mail->Host = "tls://smtp.gmail.com"; 
$mail->SMTPAuth = true;        
$mail->Username = '********@gmail.com';     
$mail->Password = '********';       

$mail->Port = 587;         

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->AddAddress('[email protected]', 'Joe User');  
$mail->addReplyTo('[email protected]', 'Information'); 

$mail->isHTML(true);         
$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
echo 'Message could not be sent.'; 
echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
echo 'Message has been sent'; 
} 
?> 

Pls helfen mir, wo ich bin falsch?

+1

funktioniert Wenn Sie den Anruf 'addAddress' Kommentar aus, wird die Nachricht an alle, nicht angesprochen, so würde warum Sie erwarten, dass es funktioniert ?! Sie könnten versuchen, [die Dokumente zu lesen] (https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting), die von der Fehlermeldung verbunden sind, die Sie erhalten. – Synchro

+0

aber beim Auskommentieren von $ mail-> AddAddress() gibt es einen Fehler: SMTP connect() fehlgeschlagen – DestylioHarsha

+1

Sie können nicht einmal versuchen, zu senden, wenn Sie keinen Empfänger festlegen, ist es nicht die Einstellung verursacht den Verbindungsfehler! – Synchro

Antwort

1

Möglicherweise haben Sie vergessen, den SMTP-Zugriff (dies ist ein Teil des IMAP-Zugriffs in den Einstellungen) für Ihr Google Mail-Konto zu aktivieren.

Außerdem ist "tls: //smtp.gmail.com" keine gültige SMTP-Serveradresse. Verwenden Sie $mail->SMTPSecure = "tls";, wenn Sie TLS verwenden möchten.

+0

SMTP-Zugriffseinstellungen erledigt, aber nicht funktioniert – DestylioHarsha

+0

@DestylioHarsha Okay, das ist ein Anfang. Siehe meine aktualisierte Antwort. – Chris

+0

https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps show $ mail-> Host = 'smtp.gmail.com'; – abkrim

0

Vielen Dank für Ihre Anregungen, dann ist es wirklich zu schätzen :-)

habe ich die Lösung wie folgt ist.

1>give Absolute path for PHPMailerAutoload.php 
2>host name as "localhost" 
3>create dummy emailId on server 



<?php 
require'/home/username/public_html/phpmailertesting/PHPMailer/PHPMailerAutoload.php'; 
$mail = new PHPMailer; 
$mail->SMTPDebug =3;        // Enable verbose debug output 
$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'localhost'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = '*****';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 
$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('*******@gmail.com');    // Name is optional 
//$mail->addReplyTo('[email protected]', 'Information'); 
//$mail->addCC('*******@gmail.com'); 
//$mail->addBCC('[email protected]'); 
//$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 
$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 
if(!$mail->send()) { 
echo 'Message could not be sent.'; 
echo 'Mailer Error: ' . $mail->ErrorInfo; 
exit(); 
} else { 
echo 'Message has been sent'; 
} 
?> 
0

CPanel blockiert standardmäßig den Zugriff auf externe SMTP-Server.

Diese Einschränkung in whm Deaktivieren> Sicherheits-Center> SMTP Einschränkungen deaktivieren

Diese

<?php 
require_once('./class.phpmailer.php'); 
$mail = new PHPMailer(); // create a new object 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages       only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "smtp.mail.yahoo.com"; 
$mail->Port = 465; // or 587 
$mail->IsHTML(true); 
$mail->Username = "[email protected]"; 
$mail->Password = "xxxxxx"; 
$mail->SetFrom("[email protected]"); 
$mail->Subject = "Test"; 
$mail->Body = "hello"; 
$mail->AddAddress("[email protected]"); 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message has been sent"; 
}?>