This is the code that I am using to send mail. But to have line breaks in message that is to be delivered in mail is not inserting new lines. I tried using "
","/n","/r/n". But i am getting these along with the message or else message is not at all getting delivered.
<?php
$to="******";
$sub="contact_details";
$userdetails="Name:".$_REQUEST["name"];
$userdetails.="<br/>Phone number:".$_REQUEST["phone"];
$userdetails.="<br/>Email:".$_REQUEST["email"]";
$userdetails.="<br/>Message:".$_REQUEST["message"].`"<br>"`;
if($_REQUEST["name"] && $_REQUEST["phone"] && $_REQUEST["email"] && $_REQUEST["message"])
{
$mail=mail($to,$sub,$userdetails);
if($mail){
echo "<script type='text/javascript'>alert('Submitted Successfully!')
</script>";
}
else{
echo"<script type='text/javascript'>alert('Failed!')</script>";
}
}
else {
echo "<script type='text/javascript'>alert('Please enter all fields!');
</script>";
}
?>
Thanks in advance.
The email that you are sending is not html supported, yow will need to add and in order to make the html work, you will need to add headers like this:
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "
";
$headers .= "Content-type:text/html;charset=UTF-8" . "
";
// More headers
$headers .= 'From: <webmaster@example.com>' . "
";
$headers .= 'Cc: myboss@example.com' . "
";
mail($to,$subject,$message,$headers);
You have to correct the syntax for errors, you have added extra "(double quote) after email, remove this, and you can use " " for adding the line breaks.
<?php
$to="******";
$sub="contact_details";
$userdetails="Name:".$_REQUEST["name"]. "
";
$userdetails.="<br/>Phone number:".$_REQUEST["phone"]. "
";
$userdetails.="<br/>Email:".$_REQUEST["email"]. "
";
$userdetails.="<br/>Message:".$_REQUEST["message"]. "
";
?>
Also header are not mandatory to send the mail, you can send the mail even if header are not set.