-2

I am using PHPmailer now for the first time, because I need to use attachments in future and the build in mail is not so good for that.

I am playing around with the example code and eventhough I get no errors + Message has been sent no messages arrive at the destination email.

Here is the code I use. The uncommented things can be ignored (I need them for a form, on submit an email should be 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;
    }
}

I tryed now different things, it seems it does not matter whether I use server PW etc. I assume its only for localhost.

EDIT:

To clarify, I am not on localhost. I have the data for my server, but obviously I dont include the data in the question. I changed them to USER, SERVER and PW. But it does not matter whether they are there or uncommented I get Message has been sentin both cases.

Roman
  • 3,563
  • 5
  • 48
  • 104

2 Answers2

0

do you really need that to be done in your local host. instead you can deploy the code in any host and check. you don't have to use any additional stuff. simple mail option is enough. reason is in your local server no mail server configured. so you using some other class to achieve that.

aruntheimperfect
  • 231
  • 1
  • 3
  • 11
-1

Did you checked on Server host ?

Niru
  • 1
  • 4