0

Please I need help with my php mailer code there is something I’m not doing correctly I was trying to add smtp to my php mailer but my code always show blank and white please help

I need help adding the smtp mailer code and from stoping my page from showing white each time smtp code is added.

I will appreciate any help provided thanks



    <?php


use PHPMailer\PHPMailer\PHPMailer;

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

$mail->isSMTP();
$mail->Host = 'smtp.mailtrap.io';
$mail->SMTPAuth = true;
$mail->Username = 'paste one generated by Mailtrap';
$mail->Password = 'paste one generated by Mailtrap’
$mail->SMTPSecure = 'tls';
$mail->Port = 2525;

  //send email    

// Turn this off when debugging and devloping
//error_reporting(0);

// Mail values
$fromName        =  trim($_POST["fromName"]);
$fromEmail       =  trim($_POST["fromEmail"]);
$toEmail         =  trim($_POST["toEmail"]);
$cc              =  trim($_POST["cc"]);
$bcc             =  trim($_POST["bcc"]);
$subjectLine     =  trim($_POST["subjectLine"]);

// Message Values
$richMessageText =  $_POST["richMessageText"];
$rawMessageText  =  $_POST["rawMessageText"];
$message         =  "";
$messageErrorSet = false;

// Attatchment
$path            = "uploads/";
$path            = $path . basename( $_FILES['attachment']['name']);
$fileTempName    = $_FILES['attachment']['tmp_name'];
$fileUploaded    = 0; // 0 = no upload, 1 = upload success, 2 = upload failure
$attatchError    = "";
    
// File attacher + error handler
if (!empty($fileTempName)) { //checks to see if a file was attatched
    // Attempt to upload file
    if(move_uploaded_file($fileTempName, $path)) {
        $fileUploaded = 1; // success
    } else {
        $fileUploaded = 2; // failure
        $attatchError = "Your message was not sent. There was an error uploading your attachment. Make sure that your php.ini file within your web server allows for file uploads, and that it allows for the upload size of your attatched file. Check out <a href='https://mediatemple.net/community/products/dv/204403894/how-can-i-edit-the-php.ini-file'>this guide</a> to make changes to the php.ini file.";
    }
}

// Store the right message body as the $message var
// If value exists for ritch text but not raw sore rich message text as $message
if(!empty($richMessageText) && empty($rawMessageText)) {
    $message = $richMessageText;
}
// If value exists for raw text but not ritch store raw message text as $message
elseif (empty($richMessageText) && !empty($rawMessageText)) {
    $message = $rawMessageText;
// If values exist for both then throw an error and update the error text
} elseif (!empty($richMessageText) && empty(!$rawMessageText)){
    $messageErrorText = "Your message was not sent. You have entered content into both the rich text editor and the raw text. Please return to the form and only use one.";
    $messageErrorSet = true;
} else {
    $messageErrorText = "Your message was not sent. It appears as if you did not enter any content into the message text area. Make sure that you go back and input content here.";
    $messageErrorSet = true;
}

  //send email

                 require_once "PHPMailer/PHPMailer.php";
              require_once 'PHPMailer/Exception.php';
              

// This code was brorrowed from the PHPMailer github page as an example useage
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Recipients
    $mail->setFrom($fromEmail, $fromName);
    $mail->addAddress($toEmail);
    // Add cc to header if there is a value in either
    if (!empty($cc)) {
        $mail->addCC($cc);
    }
    // Add bcc to header if there is a value
    if (!empty($bcc)) {
        $mail->addBCC($bcc);
    }
    //Attachments
    if (!empty($fileTempName)) {        //checks to see if a file was attatched
        $mail->addAttachment($path);    // Add attachments
    }
    //Content
    $mail->isHTML(true);                // Set email format to HTML
    $mail->Subject = $subjectLine;
    $mail->Body    = $message;

    // Send Mail using values
    if ($fileUploaded == 2) {
        //dont send message
    } else {
        $mail->send();
        //SUCESS mailed message
        echo "
        <div class=\"col-md-6 offset-md-3\">
            <div class=\"alert alert-success\" role=\"alert\">
                <strong>Email Sent!</strong> Email has been sent. Keep in mind that if you used the rich text editor, the message may appear slightly different in the actual email. Thanks for using Tramadol Xnet Spoofer!
            </div>
        </div>
        ";
    }

    // Failure message sent
} catch (Exception $e) {
    echo "
        <div class=\"col-md-6 offset-md-3\">
            <div class=\"alert alert-danger\" role=\"alert\">
                <p><strong>Awe Snap! </strong>Your message was not sent. Something went wrong with the PHP mail() function and is returning a value of FALSE. Chances are if you are seeing this message it means that it could not reach out to the SMTP server. Make sure that the webserver you are running is configured to also point to a mail server.</p>
            </div>
        </div>
    ";
}

// SUCESS AND ERROR MESSAGES


// If message error is true display error
if ($messageErrorSet == true) {
    echo "
    <div class=\"col-md-6 offset-md-3\">
        <div class=\"alert alert-danger\" role=\"alert\">
            <p><strong>Awe Snap! </strong>".$messageErrorText."</p>
        </div>
    </div>
    ";
}
// If attat error
if ($fileUploaded == 2){
    echo "
    <div class=\"col-md-6 offset-md-3\">
        <div class=\"alert alert-danger\" role=\"alert\">
            <p><strong>Awe Snap! </strong>" . $attatchError . "</p>
        </div>
    </div>
    ";
}


?>

Progman
  • 16,827
  • 6
  • 33
  • 48
  • 1
    "white page" is not a valid debugging output. You have debugging functions. Why haven't you turned them on to see where in your code the problem starts? Have you verified where in the code flow the logic error is occurring? What troubleshooting *have* you done? – schroeder May 26 '22 at 11:51
  • You might want to check https://stackoverflow.com/questions/845021/how-can-i-get-useful-error-messages-in-php – Progman May 26 '22 at 11:57
  • Honestly speaking I haven’t done any troubleshooting – tramadol xnet May 26 '22 at 12:16
  • The error occurred when adding smtp code – tramadol xnet May 26 '22 at 12:17
  • If the smtp code is removed the page will be stable and working fine – tramadol xnet May 26 '22 at 12:17
  • The white page has to do with the smtp code I believe – tramadol xnet May 26 '22 at 12:19
  • This is the cause of the white page $mail->isSMTP(); $mail->Host = 'smtp.mailtrap.io'; $mail->SMTPAuth = true; $mail->Username = 'paste one generated by Mailtrap'; $mail->Password = 'paste one generated by Mailtrap’ $mail->SMTPSecure = 'tls'; $mail->Port = 2525; – tramadol xnet May 26 '22 at 12:21
  • did you actually supply a password? or are you literally using `paste one generated by Mailtrap` ? – schroeder May 26 '22 at 13:01
  • I am not using mailtrap I am using gmail smtp or webmail smtp – tramadol xnet May 26 '22 at 14:29
  • I have arranged the code the page is now showing but smtp not working I will past it on here – tramadol xnet May 26 '22 at 14:30
  • // Message Values $richMessageText = $_POST["richMessageText"]; $rawMessageText = $_POST["rawMessageText"]; $message = ""; $messageErrorSet = false; // Attatchment $path = "uploads/"; $path = $path . basename( $_FILES['attachment']['name']); $fileTempName = $_FILES['attachment']['tmp_name']; $fileUploaded = 0; // 0 = no upload, 1 = upload success, 2 = upload failure $attatchError = ""; – tramadol xnet May 26 '22 at 14:33
  • // File attacher + error handler if (!empty($fileTempName)) { //checks to see if a file was attatched – tramadol xnet May 26 '22 at 14:33
  • // Attempt to upload file if(move_uploaded_file($fileTempName, $path)) { $fileUploaded = 1; // success } else { $fileUploaded = 2; // failure $attatchError = "Your message was not sent. There was an error uploading your attachment. Make sure that your php.ini file within your web server allows for file uploads, and that it allows for the upload size of your attatched file. Check out this guide to make changes to the php.ini file."; } – tramadol xnet May 26 '22 at 14:33
  • } // Store the right message body as the $message var // If value exists for ritch text but not raw sore rich message text as $message if(!empty($richMessageText) && empty($rawMessageText)) { $message = $richMessageText; } // If value exists for raw text but not ritch store raw message text as $message elseif (empty($richMessageText) && !empty($rawMessageText)) { $message = $rawMessageText; // If values exist for both then throw an error and update the error text } – tramadol xnet May 26 '22 at 14:34
  • elseif (!empty($richMessageText) && empty(!$rawMessageText)){ $messageErrorText = "Your message was not sent. You have entered content into both the rich text editor and the raw text. Please return to the form and only use one."; $messageErrorSet = true; } else { $messageErrorText = "Your message was not sent. It appears as if you did not enter any content into the message text area. Make sure that you go back and input content here."; $messageErrorSet = true; } – tramadol xnet May 26 '22 at 14:34
  • /send email require_once "PHPMailer/PHPMailer.php"; require_once 'PHPMailer/Exception.php'; // This code was brorrowed from the PHPMailer github page as an example useage $mail = new PHPMailer(true); try { $mail = new PHPMailer(); $mail->IsSMTP(true); $mail->Mailer = 'smtp'; $mail->Host = 'localhost'; $mail->Host = "mail.privateemail.com"; $mail->SMTPAuth = true; $mail->SMTPAutoTLS = true; $mail->Port = 465; $mail->Username = "lfreeman@onaccho.org"; $mail->Password = "yebshs"; // SMTP password – tramadol xnet May 26 '22 at 14:35
  • //Recipients $mail->setFrom($fromEmail, $fromName); $mail->addAddress($toEmail); // Add cc to header if there is a value in either if (!empty($cc)) { $mail->addCC($cc); } // Add bcc to header if there is a value if (!empty($bcc)) { $mail->addBCC($bcc); } //Attachments if (!empty($fileTempName)) { //checks to see if a file was attatched $mail->addAttachment($path); // Add attachments } – tramadol xnet May 26 '22 at 14:36
  • //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = $subjectLine; $mail->Body = $message; // Send Mail using values if ($fileUploaded == 2) { //dont send message } else { $mail->send(); //SUCESS mailed message echo "
    – tramadol xnet May 26 '22 at 14:36
  • // Send Mail using values if ($fileUploaded == 2) { //dont send message } else { $mail->send(); //SUCESS mailed message echo "
    Email Sent! Email has been sent. Keep in mind that if you used the rich text editor, the message may appear slightly different in the actual email!
    "; }
    – tramadol xnet May 26 '22 at 14:37
  • Failure message sent } catch (Exception $e) { echo "

    Awe Snap! Your message was not sent. Something went wrong with the PHP mail() function and is returning a value of FALSE. Chances are if you are seeing this message it means that it could not reach out to the SMTP server. Make sure that the webserver you are running is configured to also point to a mail server.

    ";
    – tramadol xnet May 26 '22 at 14:37
  • I have managed to fixed the code but the issue now is my mails are showing sent but nothing was delivered to my mailbox or spam box – tramadol xnet May 26 '22 at 15:45
  • Lol incorrect password – tramadol xnet May 27 '22 at 17:23
  • Even my mail domain is not correct – tramadol xnet May 27 '22 at 17:24
  • I have fixed the problem, please does any one have any idea why the code above can’t spoof an email that doesn’t have DMARC? Please share – tramadol xnet May 27 '22 at 17:26
  • The only problem is that it can’t spoof from address. Please help any help is appreciated – tramadol xnet May 27 '22 at 17:28
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 05 '22 at 21:28
  • My php mailer is showing from my website when I used smtp please is there a way a header can be added for it not to show my website or mask my website please? – tramadol xnet Jun 06 '22 at 23:54

0 Answers0