rwahdan1978 Posted Thursday at 07:31 AM Share Posted Thursday at 07:31 AM Hi I am trying to send email through php as html template. Below code, if I put the headers it will get the custom error message that the email is not sent. If I remove the headers it will send the email but the email will be not formatted as html and it will send the whole template.php as a text. $to = $myusername; $subject = "OTP - RESET PASSWORD"; $headers = array( 'MIME-Version' => '1.0', 'Content-type' => 'text/html;charset=UTF-8', 'From' => '[email protected]', 'Reply-To' => '[email protected]' ); //$message = "hi!"; ob_start(); include("mail-template.php"); $message = ob_get_contents(); ob_end_clean(); $sent = mail($to, $subject, $message); if(!$sent){ echo "Error: Message not sent. Please try again"; }else{ echo "Message was sent successfully"; } Quote Link to comment https://forums.phpfreaks.com/topic/327499-send-email-in-php/ Share on other sites More sharing options...
maxxd Posted Thursday at 11:03 PM Share Posted Thursday at 11:03 PM Highly recommend switching to a library like PHPMailer or SwiftMailer - they're both easier to use and more reliable than php's native mail function. 1 1 Quote Link to comment https://forums.phpfreaks.com/topic/327499-send-email-in-php/#findComment-1653384 Share on other sites More sharing options...
gizmola Posted yesterday at 10:49 PM Share Posted yesterday at 10:49 PM 23 hours ago, maxxd said: Highly recommend switching to a library like PHPMailer or SwiftMailer - they're both easier to use and more reliable than php's native mail function. Agree strongly with this advice. I would also suggest looking at Symfony Mailer. Quote Link to comment https://forums.phpfreaks.com/topic/327499-send-email-in-php/#findComment-1653422 Share on other sites More sharing options...
maxxd Posted 20 hours ago Share Posted 20 hours ago 4 hours ago, gizmola said: I would also suggest looking at Symfony Mailer. Yep - I got so used to saying SwiftMailer I didn't even read the link I posted. Thanks much for that! Quote Link to comment https://forums.phpfreaks.com/topic/327499-send-email-in-php/#findComment-1653427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.