Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to format php email

Tags:

php

email

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]

like image 814
forgotten Avatar asked Nov 23 '11 08:11

forgotten


People also ask

Can you use PHP in email?

PHP mail is the built in PHP function that is used to send emails from PHP scripts. It's a cost effective way of notifying users on important events. Let users contact you via email by providing a contact us form on the website that emails the provided content. You can use it to email your newsletter subscribers.

How do I fix PHP email?

If it's still not working: change the sender ($sender) to a local email (use the same email as used for recipient). Upload the modified php file and retry. Contact your provider if it still does not work. Tell your provider that the standard php "mail()" function returns TRUE, but not mail will be sent.

What is the best way to send an email from PHP?

Using the PHP mail() function. PHP's built-in mail() function is one of the simplest ways to send emails directly from the web server itself. It just takes three mandatory parameters: the email address, email subject and message body—and sends it to the recipient.

How can I add HTML email in PHP?

Use the following script. <? php $to = '[email protected]'; $subject = "Send HTML Email Using PHP"; $htmlContent = ' <html> <body> <h1>Send HTML Email Using PHP</h1> <p>This is a HTMl email using PHP by CodexWorld</p> </body> </html>'; // Set content-type header for sending HTML email $headers = "MIME-Version: 1.0" .


2 Answers

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.

like image 155
NikitaBaksalyar Avatar answered Sep 28 '22 18:09

NikitaBaksalyar


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..! :)

like image 32
aBadAssCowboy Avatar answered Sep 28 '22 18:09

aBadAssCowboy