6

I will make it really simple. I want to send an email by php. now here is code.

$line = '\n';
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;       

$to = "[email protected]";
$subject = "Umrah Booking";
$from = $mailer;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);

here is the output:

Customer Phone: 0712345678\nCustomer Last Name: Showkot

and the email is showing no sender. It says nobody.

I want the email to be look like:

Customer Phone: 0712345678
Customer Last Name: Showkot

and I also want to show that the email is from [email protected]

4 Answers 4

7

1) Change '\n' to "\n". Special characters (such as \n) are interpreted only in double-quoted strings.

2) Try to change "From:" to "From: ". Or, perhaps, variable $from has no value.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for explaining why and not just what to do. I was about to comment about why different quotes were necessary, but then you just added that.
Thank You... I just logged in to say that the problem is solved!! anyway thanks a lot :-)
6

You can use a html mail also., in that you can send a mail which is actually formatted using html.. this is very simple and yu can almost use all tags which yu use to format content in html and even css can be added..!! you need to add headers to send html mail.

here is a example..!

$to = "[email protected]";
$subject = "Test mail";
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;  
$message="
<html>
<body>
  <h1>$a</h1>: $number <br> <h1>$b</h1>: $LastName<br>
</body>
</html>";

$from = "[email protected]";
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";

mail($to,$subject,$message,$headers);

try this too., it will work..! :)

1 Comment

Thank you It already worked!! I have processed it :-) but thank you anyway for your concern!!
2
$line = "\n";
$a = "Customer Phone: ";
$b = "Customer Last Name: ";
$message = $a.$number.$line.$b.$LastName;

$to = "[email protected]";
$subject = "Umrah Booking";
$from = $mailer;
$headers = "From: " . $from. "\r\n".
'Reply-To: '. $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$message,$headers);

Comments

0

You can enter html in the message tag for example:

$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.