I want to send an HTML email using PHP. I have attempted to send the email to my Gmail account and another free email account provided by mail.com.
I am showing errors/results and my code is running and says email sent successfully. However, I am not receiving any email to either emails.
Please could anyone help improve this code in order to get it to work?
I’m brand new to learning PHP so please try and keep things simple for me if possible. Thank you.
Here is my code:
<?php
$to = '[email protected]';
$subject = 'Email with Embedded Image';
$message = '
<html>
<head>
<title>Email with Embedded Image</title>
</head>
<body>
<p>Here is an image embedded in this email:</p>
<img src="https://www.yourdomain.com/images/your-image.jpg" alt="Embedded Image">
</body>
</html>
';
$headers = "MIME-Version: 1.0" . "rn";
$headers .= "Content-type:text/html;charset=UTF-8" . "rn";
$headers .= 'From: <[email protected]>' . "rn";
$headers .= 'Reply-To: <[email protected]>' . "rn";
if(mail($to, $subject, $message, $headers)) {
echo "Email sent successfully.";
} else {
echo "Failed to send email.";
}
?>
I’ve tried testing the code for errors and I am not receiving any errors.
Mark Junior is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.