This is PHP code.
When email displays on email-id the content should be on next line.
$ToEmail = 'abc#gmail.com';
$EmailSubject = 'Exza Contact Form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name :".$_POST["name"]."\n";
$MESSAGE_BODY .= "Email :".$_POST["email"]."\n";
$MESSAGE_BODY .= "Subject : ".$_POST["subject"]."\n";
$MESSAGE_BODY .= "Message : ".nl2br($_POST["message"])."\n";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
Example:
Name : Abc
Email : abcd#gmail.com
Subject : Any
Message : All the work
Just use \r\n instead of \n.
$ToEmail = 'abc#gmail.com';
$EmailSubject = 'Exza Contact Form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name :".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "Email :".$_POST["email"]."\r\n";
$MESSAGE_BODY .= "Subject : ".$_POST["subject"]."\r\n";
$MESSAGE_BODY .= "Message : ".nl2br($_POST["message"])."\r\n";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
Related
$from = "from#domain.com";
$to = "myemail#email";
$subject ="Contact Form";
$message ="<p>Item Name: $itemname.</p>
<p>Brand: $brandname.</p>
<p>Description: $description.</p>
<p>Availability: $availability.</p>
<p>Contact Person: $contact</p>
<p>Email: $email</p>
<p>Location: $location</p>
";
$boundary = md5(time());
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from."\r\n";
$headers .= "Reply-To: ".$from."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Transfer-Encoding: 7bit"."\r\n\r\n";
$body .= "This is a MIME encoded message."."\r\n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$body .= $message ."\r\n";
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: application/octet-stream; name=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n\r\n";
$body .= $encoded_content ."\r\n";
if (#mail( $to, $subject, $body, $headers)) {
$resultMessage = '<div class="alert alert-success">Thank You. Your message has been sent</div>';
} else {
$resultMessage = '<div class="alert alert-danger">Sorry Please Try Again.</div>';
}
}
This is my form PHP code. It is used by my logged in users so users usually signup by choosing username>email>password and register then they log in and see this contact form. so I want that when they submit a form , PHP should send their Username and Email. How can I do that?
My code for sending email
<?php
$to = 'piyu.mulay#gmail.com';
$subject = 'Website Change Request';
$headers = "From: chintamani.mulay#gmail.com \r\n";
$headers .= "CC: chintamani.mulay#gmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '<img src="../1.jpg">';
$message .= '</body></html>';
echo mail($to, $subject, $message, $headers);
?>
When i put link in <img src="http://weber-steinach.de/files/339349"> it works well but when I put path of file which is in my localserver I won't show and Image in email.
Finally I come to know how to do this. Here is the source link from where I come to know
$bound_text = "----*%$!$%*";
$bound = "--".$bound_text."\r\n";
$bound_last = "--".$bound_text."--\r\n";
$headers = "From: youremail#host.com\r\n";
$headers .= "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed; boundary=\"$bound_text\""."\r\n" ;
$message = " you may wish to enable your email program to accept HTML \r\n".
$bound;
$message .=
'Content-Type: text/html; charset=UTF-8'."\r\n".
'Content-Transfer-Encoding: 7bit'."\r\n\r\n".
'
<html>
<head>
<style> p {color:green} </style>
</head>
<body>
A line above
<br>
<img src="cid:http://localhost/a/img/1.jpg">
<br>
a line below
</body>
</html>'."\n\n".
$bound;
$file = file_get_contents("http://localhost/a/img/1.jpg");
$message .= "Content-Type: image/jpeg; name=\"http://localhost/a/img/1.jpg\"\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-ID: <http://localhost/a/img/1.jpg>\r\n"
."\r\n"
.chunk_split(base64_encode($file))
.$bound_last;
echo mail($to, $subject, $message, $headers) ;
?>
I am trying to send the order form of my website in email. it is working fine but the problem is that i receive the whole information in just one single line. I want to have a line break after every field. my code is:
<?php
($_POST["email"]<>'') {
$ToEmail = 'info#mysite.com';
$EmailSubject = 'Website order form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Adress: ".nl2br($_POST["address"])."";
$MESSAGE_BODY .= "product: ".nl2br($_POST["product"])."";
$MESSAGE_BODY .= "phone: ".nl2br($_POST["phone"])."";
$MESSAGE_BODY .= "quantity: ".nl2br($_POST["quantity"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
exit;
?>
Kindly guide me where i am wrong. Thanks in advance
You need to do use \r\n if you use Content-type : text/plain
Or <br/> if you use Html
<?php
($_POST["email"]<>'') {
$ToEmail = 'info#mysite.com';
$EmailSubject = 'Website order form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."\r\n";
$MESSAGE_BODY .= "Adress: ".nl2br($_POST["address"])."\r\n";
$MESSAGE_BODY .= "product: ".nl2br($_POST["product"])."\r\n";
$MESSAGE_BODY .= "phone: ".nl2br($_POST["phone"])."\r\n";
$MESSAGE_BODY .= "quantity: ".nl2br($_POST["quantity"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
exit;
?>
I am developing a contact form for sending an email to user data,but its not working.
Code:
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'youremail#site.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader = "Reply-To: ".$_POST["email"]."\r\n";
$mailheader = "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY = "Email: ".$_POST["email"]."";
$MESSAGE_BODY = "Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Your message was sent
<?php
} else {
?>
<form action="mail.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="Comment" cols="45" rows="6" id="Comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php
};
?>
It throws an errors like:
Undefined index: commen in line 10.
header missing in line 11.
Here are some mistakes on your code..
1.at the line no 2 change the code from (i don't know why you didn't mention about this error)
if ($_POST["email"]<>'') {
to
if (isset($_POST["email"]) && $_POST["email"]<>'') {
2.change the name of the textarea from "Comment" to "comment"
and finally follow the instruction from the previous answers of this post to solve the "header missing" problem.
something like
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
As everybody told your first mistake, I am not going to repeat it but another mistake is:
You should join the mail headers and mail body:
Your previous code:
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader = "Reply-To: ".$_POST["email"]."\r\n";
$mailheader = "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY = "Email: ".$_POST["email"]."";
$MESSAGE_BODY = "Comment: ".nl2br($_POST["comment"])."";
New Code:
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
Look at the dots given before the equalto signs.
see you need to concatenate the mailHeader var same goes for body message
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
You have done the two mistakes.
In form you have given name="Comment" for please give name="comment" or $_POST["comment"] to $_POST["Comment"]
put the . after mail header.like
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
you are getting this error 10th line because you are using $_POST["comment"]" but in the form you have written id="Comment". To remove the error take care of upar and lower case in the both places..
Thank you.
I'm still struggling with this mail script - I'm now getting all the marked up html through rather than seeing it as rendered html if that makes sense?
<?php
$mailheader .= "MIME-Version: 1.0\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$formcontent .="<table border='1'>";
foreach ($_POST as $field=>$value)
{
$formcontent.="<tr>";
$formcontent .= "<td>$field:</td> <td>$value</td>";
$formcontent.="</tr>";
}
$formcontent .= '<tr><td>User-Agent: </td><td>'.$_SERVER['HTTP_USER_AGENT'].'</td>';
$formcontent .="</table>";
$recipient = "info#*******.com";
$subject = "Event feedback form";
$mailheader = "From: web.form#*******-events.co.uk\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
header("location:http://www.******-events.co.uk");
?>
Follow php's documentation:
You'll need html tags
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I'd rather use a PHP class as PHPMailer for HTML emails. And btw I will add the full HTML document tags (html, head, body, etc...) for the mail body.
I'd missed these:
$formcontent = '<html><body>';
Thanks for everyone's time and input though
Jim