1

I am trying to get a PHP email to send in an HTML format, but the current email is just sending in code. I am not sure at all what I am doing wrong.

Does anyone see anything?

ini_set('display_errors', 1);
error_reporting(E_ALL);

$project_name           = $_POST['project_name'];
$title_roll             = $_POST['title_roll'];
$project_email          = $_POST['project_email'];
$project_number         = $_POST['project_number'];
$project_description    = $_POST['project_description'];
$project_source         = $_POST['project_source'];
$project_socialMedia    = $_POST['project_socialMedia'];
$project_humanTest      = $_POST['project_humanTest'];

$to = 'email';
$subject = 'Project Inquiry Form Sent';
//$message = 'FROM: '.$project_name. "<br>" . ' Email: '.$project_email. "<br>" . 'Message: '.$project_description;
//$msgcontents = "Name: $project_name<br>Email: $project_email<br>Message: $project_description";
$message = '
    <html>
    <head>
        <title>Project Inquiry Form Sent</title>
    </head>
    <body>
        <p>Hi Optimum Designs Team,</p><br>
        <p>There has been a Project submitted. Here are the details:</p><br>
        <p>Name: '. $project_name .'</p>
        <p>Name: '. $title_roll .'</p>
        <p>Name: '. $project_email .'</p>
        <p>Name: '. $project_number .'</p>
        <p>Name: '. $project_description .'</p>
        <p>Name: '. $project_source .'</p>
        <p>Name: '. $project_socialMedia .'</p><br>
        <p>Good Luck,</p>
        <p>Administration</p>
    </body>
    </html>
';
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From:' .$project_email . "\r\n";

if (!empty($project_email)) { 
    if (filter_var($project_email, FILTER_VALIDATE_EMAIL)) { 

        //Should also do a check on the mail function
        if (mail($to, $subject, $message, $headers)) {
            echo "Your email was sent!"; // success message
        } else {
            echo "Mail could not be sent!"; // failed message
        }

    } else { 
        //Invalid email
        echo "Invalid Email, please provide a valid email address.";
    }

} else {
    echo "Email Address was not filled out.";
}

1 Answer 1

3

That's because your last header

$headers = 'From:' .$project_email . "\r\n";

is missing its concatenate

$headers .= 'From:' .$project_email . "\r\n";
         ^ right there

in turn breaking the chainlink.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.