email body not taking carriage returns [duplicate] - php

Please help me to make code message in line break. i didn't know how to do this please check my code. hope you help me out. thanks alot in advance:-
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-". $first_name . "Email:-". $mail . "Phone Number:-
".$phone. " Message:-".$msg." " ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
?>
I want to recieve message like this:-
Name:-loreal
email:- Mymail
phone Number:- 987654321
Message:- Hi

Try using \n in your message as:
$message = " Name:-". $first_name . "\n Email:-". $mail . "\n Phone Number:-
".$phone. "\n Message:-".$msg." " ;
They're escape sequences. \n is a newline and \r is a carriage return. \r is a Carriage Return \n is a Line Feed (or new line)
Mac: \r
Linux/Unix: \n
Windows: \r\n

When you are using html tags in email template then you have to mention content type in headers and you have to include that headers in mail function like this
$headers = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);

For HTML mail use proper headers:
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$message = "Name:-". $first_name . "<br/>Email:-". $mail . "<br/>Phone Number:-".$phone. "<br/>Message:-".$msg." " ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
?>

<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail = $_POST['email'];
$msg = $_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-" . $first_name . "\n\n" . "Email:-" . $mail . "\n\n" . "Phone Number:- " .$phone . "\n\n" . " Message:- " . $msg;
$headers = "From:" . $from;
$headers .= " MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
mail($to,$subject,$message,$headers);
header('Location: thank-you.php');
}
else{
echo 'Your message cannot be sent.';
}
?>

Related

How to Send email with line breaks in php

Please help me to make code message in line break. i didn't know how to do this please check my code. hope you help me out. thanks alot in advance:-
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-". $first_name . "Email:-". $mail . "Phone Number:-
".$phone. " Message:-".$msg." " ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
?>
I want to recieve message like this:-
Name:-loreal
email:- Mymail
phone Number:- 987654321
Message:- Hi
Try using \n in your message as:
$message = " Name:-". $first_name . "\n Email:-". $mail . "\n Phone Number:-
".$phone. "\n Message:-".$msg." " ;
They're escape sequences. \n is a newline and \r is a carriage return. \r is a Carriage Return \n is a Line Feed (or new line)
Mac: \r
Linux/Unix: \n
Windows: \r\n
When you are using html tags in email template then you have to mention content type in headers and you have to include that headers in mail function like this
$headers = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);
For HTML mail use proper headers:
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail=$_POST['email'];
$msg=$_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$message = "Name:-". $first_name . "<br/>Email:-". $mail . "<br/>Phone Number:-".$phone. "<br/>Message:-".$msg." " ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to,$subject,$message,$headers);
?>
<?php
if(isset($_POST['submit'])){
$to = "mymail#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$mail = $_POST['email'];
$msg = $_POST['message'];
$phone= $_POST['mob'];
$subject = "contact";
$subject2 = "Copy of your form submission";
$message = "Name:-" . $first_name . "\n\n" . "Email:-" . $mail . "\n\n" . "Phone Number:- " .$phone . "\n\n" . " Message:- " . $msg;
$headers = "From:" . $from;
$headers .= " MIME-Version: 1.0\r\n"; #Define MIME Version
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; #Set content type
mail($to,$subject,$message,$headers);
header('Location: thank-you.php');
}
else{
echo 'Your message cannot be sent.';
}
?>

How to send HTML message using PHP?

I'm trying to send the message as HTML, but it's arrived as XML Escape!!
Example in screenshot:
second problem is, if i typing the subject in "Arabic language" it's encoded in ANSI.
but if i test to send the same message via Gmail the subject be fine, but the content arrived as XML Escape!!
PHP CODE:
<?php
if(isset($_POST['submit'])){
$to = "email#gmail.com";
$from = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = $first_name . " " . $last_name . " " . "\n\n";
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
$headers = "From: Brand Name <info#my-dmoain.me>" . "\r\n";
mail($to,$subject,$message,$headers,"-f info#my-dmoain.me");
echo "Thanks";
}
?>
I cant figure out what is wrong.
Thanks
Add concat shorthand .= to this line:
$headers = "From: Ali Najm <ali-najm#iraqnaa.me>" . "\r\n";
You're reassigning $headers var.
Sending nice html with php

Html email not sending using php

I am trying to send email in html format using php file but each time i receive email with this html code instead of html format of text ... if i move header code above message its not sending email so i put it at bottom
please help ... thank you
<?php
$name = $_POST['name'];
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = "
<html>
<head>
<body>
<h1>
<center>Meeting invitation</center>
</h1>
</body>
</head>
</html>
";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=ISO-8859-1\r\n";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
You forget ".", for string
$headers = "From:" . $from;
must be
$headers .= "From:" . $from;
Please add this
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
Try below code..
<?php
$name = $_POST['name'];
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = "
<html>
<head>
<body>
<h1>
<center>Meeting invitation</center>
</h1>
</body>
</head>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <gaurav#example.com>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Here is working example of mail code in PHP:
<?php
if($_GET["submit"] = "Send" )
{
$namezz = $_GET["name"];
$emailzz = $_GET["email"];
$cityzz = $_GET["city"];
$phonenozz = $_GET["phoneno"];
$subj = $_GET["subject"];
$commentszz = $_GET["msg"];
}
ini_set("SMTP","www.cccccc.in");
// email address to whoon to send
$email = "ccc#gmail.com";
// The subject
if( $subj == "No-Subject")
{
$subj = "New Enquiry form form ". $namezz;
$subject = $subj;
}
else
{
$subject = $subj;
}
// The message
$msgg = "Name :".$namezz ."\n
Email :".$emailzz ."\n
City :".$cityzz ."\n
Phone Number :".$phonenozz ."\n
Subject:".$subj ."\n
Message :".$commentszz;
$headers = "from :".$emailzz;
mail($email, $subject, $msgg, $headers);
echo 'thanks for sending email';
?>
Hope this will help you.
You could something along the lines of
<?php
$val=mail('your email address', $_POST['subject'], $_POST['message']);
?>
<p>Your email has been sent.</p>
With the html page containing
<input type="text" id="inputEmail" placeholder="Email" name="subject">
<textarea id="textarea" rows="10" name="message" placeholder="Entermsg:"></textarea>
Using the mail function in PHP is simple and straight forward
In your code you'll need to modify
$headers .= "From:" . $from;
You forgot to put a . in this piece of code
$headers = "From:" . $from;
So this is your final code
$headers .= "From:" . $from;
Because the . is used to concatenate in PHP.

PHP - need help in php form element (Header part)

I am a beginner in php.
I am trying php to send mail.
My mail goes to mail client but it does not show the header part well as I wanted.
I am using the following codes ----
<?php
//validation expected data exists
if(!isset($_POST["name"]) ||
!isset($_POST["city"]) ||
!isset($_POST["email"]) ||
!isset($_POST["phone"]) ||
!isset($_POST["message"])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
//Subject
$name = $_POST["name"];
$subject = "NO REPLY";
$email = $_POST["city"];
$phone = $_POST["email"];
$website = $_POST["phone"];
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = 'info#mishmihillsadventure.in';
$send_contact=mail($to,$subject,$message,$header);
//Check, if message sent to your email
// Display message "We've recived your information"
if($send_contact){
echo "We've received your contact information";
}
else{
echo "ERROR";
}
?>
$email = $_POST["city"];
$phone = $_POST["email"];
Is this really what you want? Shouldn't it be:
$email = $_POST["email"];
And try the following headers:
$header = 'From: ' . $name . '<' . $email . '>' . "\r\n";
Use (atmost) following headers while sending mail via PHP -
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header .= "From: $name <$email>" . "\r\n";
//If want to `CC` someone add
$header .= 'Cc: abc#email.com' . "\r\n";
Using variables in Double quotes is fine.
You can try something like in code mentioned below,
<?php
$to = 'test#to.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: test#from.com' . "\r\n" .
'Reply-To: test#from.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
echo 'Msg send..';
} else {
echo 'Msg Not send..';
}
?>

PHP script to send contact form to inbox

I have created a contact form and I would like for the details be sent to my inbox once the submit button is clicked. Clicking the submit button opens up a new mail page (see getfreepack.org). I have been advised I need a PHP script. I copied one off the web but no too sure how to use it to my advantage. I would appreciate your help.
$Name= $_REQUEST["Name"];
$Email = $_REQUEST["Email"];
$Phone = $_REQUEST["Phone"];
$JobTitle = $_REQUEST["Jobtitle"];
$KeySkills = $_REQUEST["Keyskills"];
$Attachment = $_REQUEST["Attachment"];
$to = "my email address#mail.com";
$subject = "Contact Form";
$message = "Name: " . $Name $message .= "\Email: " . $Email: $message .= "\n Phone: " . $ Phone;
$message .= "\nSubject: " . $Subject; $message .= "\nCover Letter: " . $CoverLetter;
$message .= "\n Attachment: " . $Attachment; $message .= "\nIP Adress: " . $_SERVER['REMOTE_ADDR'];
$message .= "\nBrowser: " . $_SERVER['HTTP_USER_AGENT'];
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";
$sentOk = mail($to,$subject,$message,$headers);
echo "sentOk=" . $sentOk;
A very basic one would be :
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
If you want to go one step more check out the manual : http://php.net/manual/en/function.mail.php
Cheers
You don't need the php to get a form to send to your email address make the form tag like this:
>>action="mailto:youremailaddress#whatever.com">
Input
Input

Categories