来自PHP的HTML电子邮件

来自PHP的HTML电子邮件,php,html,Php,Html,我是个新手,基本上使用了我在网上看到的示例和教程。任何帮助都将不胜感激 我有一个简单的web表单,可以通过HTML表格发送电子邮件 它不会发送邮件正文,也不会发送邮件,除非我使用$email\u body而不是$message HTML表单: <section class="left"> <form name="input" action="appointment.php" method="post"> <p

我是个新手,基本上使用了我在网上看到的示例和教程。任何帮助都将不胜感激

我有一个简单的web表单,可以通过HTML表格发送电子邮件

它不会发送邮件正文,也不会发送邮件,除非我使用
$email\u body
而不是
$message

HTML表单:

<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




$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;
  }
}


?>

姓名:



电子邮件:



问题:

保持简短。。 首选时间:



早上(8:30-9:55)



午餐时间 放学后(3:10-3:45)



PHP:

<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




$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;
  }
}


?>
更改

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


只需在
邮件($to、$email\u subject、$email\u body、$headers)之前添加这一行即可


我不认为你在传递信息。看看$emai_body和$message在代码中是如何不相关的。
mail($to,$email_subject,$message,$headers);
$email_body .= $message;