PHPmailer成功发送电子邮件,未收到任何电子邮件

时间:2017-12-19 10:03:41

标签: php email

我现在第一次使用PHPmailer,因为我将来需要使用附件,mail中的构建对此不太好。

我正在玩示例代码和事件虽然没有错误+ Message has been sent没有消息到达目标电子邮件。

这是我使用的代码。可以忽略未注释的内容(我需要它们用于表单,提交电子邮件时应该发送)

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require '../vendor/autoload.php';

// Fetching Values from URL.
//$phone = $_POST['phone1'];
//$email_var = $_POST['email1'];
$email_var = 'sender.email.info@gmx.net';
$email_var = filter_var($email_var, FILTER_SANITIZE_EMAIL); // Sanitizing E-mail.

// After sanitization Validation is performed
if (filter_var($email_var, FILTER_VALIDATE_EMAIL)) {

    $mail = new PHPMailer();                              // Passing `true` enables exceptions
    try {

        //$mail->SMTPDebug = 2;                                 // Enable verbose debug output
        //$mail->isSMTP();                                      // Set mailer to use SMTP
        //$mail->Host = 'SERVER';               // Specify main and backup SMTP servers
        //$mail->SMTPAuth = true;                               // Enable SMTP authentication
        //$mail->Username = 'USER';                          // SMTP username
        //$mail->Password = 'PW';                           // SMTP password
        //$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
        //$mail->Port = 465;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('receiver.email@gmx.net');
        //$mail->addAddress('receiver.email@gmx.net');     // Add a recipient


        //Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

        //Content
        $mail->isHTML(true);                                  
        $mail->Subject = 'Here is the subject';
        $mail->Body    = '<div style="padding:50px; color:white;">'
                        . '<br/> Kautionsrückzahlung Interesse von: <br/><br/>'
                        //. 'Telefon: ' . $phone . '<br/>'
                        . 'Email: ' . $email_var . '<br/>';

        $mail->AltBody = '<div style="padding:50px; color:white;">'
                        . '<br/> Kautionsrückzahlung Interesse von: <br/><br/>'
                        //. 'Telefon: ' . $phone . '<br/>'
                        . 'Email: ' . $email_var . '<br/>';

        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
}

我现在尝试了不同的东西,看起来我是否使用服务器PW等并不重要。我认为它只适用于localhost。

编辑:

澄清一下,我不在本地主机上。我有我的服务器的数据,但显然我不包括问题中的数据。我将其更改为USERSERVERPW。 但无论是在那里还是取消注释都没关系我在两种情况下都得到Message has been sent

2 个答案:

答案 0 :(得分:0)

你真的需要在你当地的主人那里完成。相反,您可以在任何主机中部署代码并检查。你不必使用任何额外的东西。简单的邮件选项就足够了。原因是在本地服务器中没有配置邮件服务器。所以你使用其他类来实现它。

答案 1 :(得分:-1)

您是否检查过服务器主机?

相关问题