Jump to content

Email sent with email form doesn't recognize paragraphs


RuiMelo

Recommended Posts

I've just built a php email form to connect with a form inside a html page.

 

This is the php code:

<?php
$html = htmlspecialchars($utf8_string, ENT_COMPAT, 'iso-8859-1');
if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = $_POST['email_to_'];
    $email_subject =  mb_convert_encoding($_POST['subject'], 'iso-8859-1');
    //$email_subject = mb_convert_encoding($content, 'UTF-8'); 
     
    function died($error) {
        // your error code can go here
	echo "<script language=\"javascript\" type=\"text/javascript\"> alert('Pedimos desculpa, mas foram encontrados erros nas informacoes que submeteu. $error');window.location = \"http://animal.org.pt/email3.html\";</script>";

        /*echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";*/
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
	!isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('Pedimos desculpa, mas foram encontrados erros nas informacoes que submeteu.');       
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= '\n\nO Endereco de Email nao e valido!\n';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'O Nome que sumeteu nao e valido!\n';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'O Apelido que sumeteu nao e valido!\n';
  }
  /*if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }*/
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    //$email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= clean_string($comments); 
    $email_message .= clean_string($first_name)." ";
    $email_message .= clean_string($last_name)."\n";
    $email_message .= clean_string($email_from)."\n";
    $email_message .= clean_string($telephone)."\n";
    
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  

echo "<script language=\"javascript\" type=\"text/javascript\">
alert('Obrigado pela sua mensagem!');
window.location = \"http://$_SERVER[HTTP_HOST]\";
</script>
";
?>
?>

<!-- include your own success html here -->

<?php
}
?>

 

 

 

 

 

This is the html code:

<div class="email_form"><table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="500" class="cushycms" title="Mensagem do Email a apresentar na página"><h1>Your Message</h1><br/>
<span id="messageStyle">Please adopt a policy to prevent severe animal suffering<br/>
Dear [Name of University President], <br/></td>
<td width="50"></td>
    <td width="250"><span id="formStyle"><form name="contactform" method="post" action="form1.php">
        <b>Informações do contacto:</b><br><br />
        Nome:<br />
        <input type="text" name="first_name" size="35"><br><br>
        Apelido:<br />
        <input type="text" name="last_name" size="35"><br><br>

        Email:<br>
        
        <input type="text" name="email" size="35"><br><br>
        Cidade:<br>
        
        <input type="text" name="telephone" size="35"><br><br>
        Todos os campos são obrigatórios.
        <br><br>
        <textarea id="subjct" rows="1" name="email_to_" cols="30" class="cushycms" title="Email do Destinatário">rui_melo_work@hotmail.com</textarea>
        <textarea id="subjct" rows="1" name="subject" cols="30" class="cushycms" title="Títulos do Email">Animal Protecção Fárú téparamekla í‏</textarea>
        <textarea id="textArea" rows="9" name="comments" cols="30" class="cushycms" title="Mensagem do Email enviada pelo servidor">
        Please adopt a policy to prevent severe animal suffering
Dear [Name of University President],
I am deeply concerned that my tax dollars may be contributing to research at your institution that causes severe animal suffering.
As a stakeholder in your university, I urge you to adopt a written policy prohibiting severe pain and distress in all laboratory animals in your care.
Animals used in research at your institution deserve to be protected from severe suffering.
Federal laws such as the Animal Welfare Act and Public Health Service Policy, as well as accreditation organizations such as the Association for Assessment and Accreditation of Laboratory Animal Care do not prohibit research or conditions that cause severe and unrelieved pain and distress.
Adopting a specific policy preventing severe and unrelieved suffering is the only way to assure donors, students, alumni, faculty, staff, parents and taxpayers that animals in your care are not being subjected to severe suffering.
If your school already has a policy or would like to adopt one, please contact The Humane Society of the United States at www.humanesociety.org/campuspolicycontact. 

Thank you for your consideration.

Sincerely,
        </textarea>
        <input type="submit" value=" Enviar " name="submit">
  </form></span></td>
  </tr>
</table>
    </div>

 

 

The problem is that the email sent by this system doen't accept paragraphs and is shown like this in the inbox of a gmail or hotmail account:

<p>

      Please adopt a policy to prevent severe animal suffering Dear [Name of University President],</p>

I am deeply concerned that my tax dollars may<br />

<br />

<br />

be contributing to research at your institution that causes severe animal suffering. As a stakeholder in your university, I urge you to adopt a written policy prohibiting severe pain and distress in all laboratory animals in your care. Animals used in research at your institution deserve to be protected from severe suffering. Federal laws such as the Animal Welfare Act and Public Health Service Policy, as well as accreditation organizations such as the Association for Assessment and Accreditation of Laboratory Animal Care do not prohibit research or conditions that cause severe and unrelieved pain and distress. Adopting a specific policy preventing severe and unrelieved suffering is the only way to assure donors, students, alumni, faculty, staff, parents and taxpayers that animals in your care are not being subjected to severe suffering. If your school already has a policy or would like to adopt one, please contact<br />

The Humane Society of the United States at www.humanesociety.org/campuspolicycontact.<br />

Thank you for your consideration.<br />

Sincerely, R

 

I need urgent help!!! thank you

Link to comment
Share on other sites

Well all your input is being bunched together into $email_message.  I would make each a variable and then create an html outline for your email.  I'm currently using this outline for a school site.

  $mailmsg="<p>Dear $usersname,<br />$message.<br />Thank You</p>";

    $mail_to = "$siteusers";

    $mail_subject = "$subject";

    $mail_body = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body><center><table width=98% border=\"0\" align=\"center\" cellpadding=1 cellspacing=\"0\" ><tr><td align=\"center\" valign=\"top\"><table width=98% border=\"0\"  cellpadding=\"0\" cellspacing=\"0\" style='border:2px solid; border-color:#737772'><tr><td><img src=\"$siteurl/images/fullbanner.png\" border=\"0\" width=\"100%\" height=\"128\" /></td></tr><tr><td bgcolor=\"#FFFFFF\" align=\"left\" style=\"padding:14px;\">$mailmsg</td></tr><tr><td bgcolor=#838E7D align=\"center\" style=\"padding:2px; border-top:2px solid; border-color:#737772\"><a href=\"$siteurl\" style='color:#ffffff; text-decoration:none'>$sitename</a></td></tr></table></td></tr></table></center></body></html>";

$headers = "From: $siteemail\r\n";

$headers .= "Reply-To: $siteemail\r\n";

$headers .= "Organization: $schoolname \r\n";

$headers .= "X-Sender: $siteemail \r\n";

$headers .= "X-Priority: 3 \r\n";

$headers .= "X-Mailer: php\r\n";

$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    mail($mail_to, $mail_subject, $mail_body, $headers);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.