1

I’m fairly new and basically using examples and tutorials I’ve seen on the web. Any help would be appreciated.

I’ve got a simple web form to email with an HTML table.

It won’t send the body of the message and it won’t send the message at all unless I use $email_body rather than $message.

HTML Form:

<section class="left"> <form name="input" action="appointment.php" method="post"> <p>Name:</p> <input name="name" type="text"/><br><br> <p>Email:</p> <input name="email" type="text"/><br><br> <p>Issue:</p> <textarea name="issue" rows="4" cols="50">Keep it brief.. </textarea> </section> <section class="right"> <p><u>Preferred Time(s):</u></p><br><br> <p><input type="radio" name="checkmorning" value="Available">Morning (8:30-9:55)</p><br><br> <p><input type="radio" name="checklunch" value="Available">Lunchtime</p><br><br> <p><input type="radio" name="checkafter" value="Available">After School(3:10-3:45)</p><br><br> <input type="submit" value="Submit"> </section> </form> 

PHP:

<?php $name = $_POST['name']; $visitor_email = $_POST['email']; $issue = $_POST['issue']; $checkmorning = $_POST['checkmorning']; $checklunch = $_POST['checklunch']; $checkafter = $_POST['checkafter']; $email_from = '*****@gmail.com';//<== update the email address $email_subject = "New Order submission"; $email_body = '<html><body>'; $message .= '<img src="*******" alt="New Appointment" />'; $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; $message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>"; $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>"; $message .= "<tr><td><strong>Issue:</strong> </td><td>" . strip_tags($_POST['issue']) . "</td></tr>"; $message .= "<tr><td><strong>TIME: Morning:</strong> </td><td>" . $_POST['checkmorning'] . "</td></tr>"; $message .= "<tr><td><strong>TIME: Lunchtime:</strong> </td><td>" . $_POST['checklunch'] . "</td></tr>"; $message .= "<tr><td><strong>TIME: After School:</strong> </td><td>" . $_POST['checkafter'] . "</td></tr>"; $message .= "</table>"; $message .= "</body></html>"; $to = "***@gmail.com";//<== update the email address $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; //Send the email! mail($to,$email_subject,$email_body,$headers); //done. redirect to thank-you page. header( 'Location:/thank-you.html' ); if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?> 
1
  • I don't think you're sending the message. Look how $emai_body and $message are unrelated in your code. Commented Jan 30, 2014 at 12:16

2 Answers 2

3

change

$email_body = '<html><body>'; 

to

$message = '<html><body>'; 

and

mail($to,$email_subject,$email_body,$headers); 

to

mail($to,$email_subject,$message,$headers); 
Sign up to request clarification or add additional context in comments.

Comments

0

just add this line before mail($to,$email_subject,$email_body,$headers);

$email_body .= $message; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.