2017-05-18 2 views
0

Warum Fehler beim Senden von E-Mails mit phpMailer?Warum Fehler beim Senden von Mail mit phpMailer?

<?php 
    require 'PHPMailerAutoload.php'; 

    $mail = new PHPMailer; 

    $mail->isSMTP();          // Set mailer to use SMTP 
    $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
    $mail->SMTPAuth = true;        // Enable SMTP authentication 
    $mail->Username = '[email protected]';     // SMTP username 
    $mail->Password = 'secret';       // SMTP password 
    $mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 

    $mail->From = '[email protected]'; 
    $mail->FromName = 'Mailer'; 
    $mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
    $mail->addAddress('[email protected]');    // Name is optional 
    $mail->addReplyTo('[email protected]', 'Information'); 
    $mail->addCC('[email protected]'); 
    $mail->addBCC('[email protected]'); 

    $mail->WordWrap = 50;         // Set word wrap to 50 characters 
    $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; 
    } else { 
     echo 'Message has been sent'; 
    } 

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

+2

Mögliche Duplikat [SMTP Connect() fehlgeschlagen funktioniert. Nachricht wurde nicht gesendet. Mailer-Fehler: SMTP Connect() fehlgeschlagen] (http://stackoverflow.com/questions/18496650/smtp-connect-failed-message-was-not-sent-mailer-error-smtp-connect-failed) –

+0

Ich sehe, Sie haben Debug-Ausgabe nicht aktiviert. Sind Sie dem Link in der Fehlermeldung sogar gefolgt? –

+0

Danke "Der Diktator" –

Antwort

-1
<?php 

    $mailto = $_POST['mail_to']; 
    $mailsub = $_POST['mail_subject']; 
    $mailmsg = $_POST['mail_message']; 
    require 'includes/PHPMailer-master/PHPMailerAutoload.php'; 
    $mail = new PHPMailer(); 
    $mail ->IsSmtp(); 
    $mail ->SMTPDebug = 1; 
    $mail ->SMTPAuth = true; 
    $mail ->SMTPSecure = 'ssl'; 
    $mail ->Host = "smtp.gmail.com";//If Your sending accound server is gmail use this else change 
    $mail ->Port = 465; // or 587 
    $mail ->IsHTML(true); 
    $mail ->Username = "[email protected]"; //use your sending mail accound address 
    $mail ->Password = "abc123"; //use the account password of the above used mail. 
    $mail ->SetFrom("[email protected]");//use your sending mail accound address (Same) 
    $mail ->Subject = $mailsub; 
    $mail ->Body = $mailmsg; 
    $mail ->AddAddress($mailto); 

    if(!$mail->Send()){ 
     echo "Mail not Send"; 
    } 
    else{ 
     echo " Mail Send"; 
    } 
?> 

Tihs-Code

Verwandte Themen