I have a form I am using to simply capture a name and email from a user. When the user submits the form an email is then fired to the specified recipient containing a link.
I had this all working but realised I needed to add a html footer to the email which was originally being read as plain text.
After doing some digging I have now tried to set the footer to read as html ,but the email no longer sends. I am not a php developer.
My question is have I missed something or am I just way off?
<?php // configure $from = 'Ether Solutions Sales <email@domain.co.uk>'; $sendTo = $_POST['remail']; $subject = "test email"; $name = $_POST['name']; $okMessage = 'your message has been sent successfully, please ask the recipient to check their inbox'; $errorMessage = 'There was an error while submitting the form. Please try again later'; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "rn"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; // Create email headers $headers .= 'From: '.$from."rn".'Reply-To: '.$from."rn" . 'X-Mailer: PHP/' . phpversion(); // Compose a simple HTML email message $message = '<html><body>'; $message .= '<p style="margin-bottom:30px;">regards dave</p>'; $message .= '<a href="http://www.domain.co.uk" title="link to domain website">www.domain.co.uk</a>'; $message .= '<p style="font-color:blue;">Office Tel: 0844 000 000</p>'; $message .= '<p style="font-color:blue;">Mobile: 0000 000 0000</p>'; $message .= '<p style="font-color:blue;">Technical Support: 0845 000 0000</p> '; $message .= '<p style="font-color:blue; font-weight:bold;">Some tagline here</p> '; $message .= '<img src="imageurl/test.png" alt="sample alt tag"/>'; $message .= '</body></html>'; // let's do the sending try { $emailText = "{$name} you have been sent an electronic document to be signed.nTo view your document please click the following link URL: /www.domain.com"; mail($sendTo, $subject, $emailText, $message, $headers, "From: " . $from); $responseArray = array('type' => 'success', 'message' => $okMessage); } catch (Exception $e) { $responseArray = array('type' => 'danger', 'message' => $errorMessage); } if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $encoded = json_encode($responseArray); header('Content-Type: application/json'); echo $encoded; } else { echo $responseArray['message']; }
Advertisement
Answer
I tested your code and got this warning:
PHP Warning: mail() expects at most 5 parameters, 6 given in /home/ruemercc/public_html/lab/email2/mail.php on line 47
I would suggest you use PHPMailer library found here phpmailer
. It will allow you to even send bulk emails(Which I think will be an added advantege in your case). Have fun coding