How to format php email

I will make it very simple. I want to send an email via php. now here is the code.

$line = '\n'; $a = "Customer Phone: "; $b = "Customer Last Name: "; $message = $a.$number.$line.$b.$LastName; $to = " forgotten_tarek@yahoo.com "; $subject = "Umrah Booking"; $from = $mailer; $headers = "From:" . $from; mail($to,$subject,$message,$headers); 

here is the result:

 Customer Phone: 0712345678\nCustomer Last Name: Showkot 

and there’s no sender in the email. He says nobody .

I want the letter to look like this:

 Customer Phone: 0712345678 Customer Last Name: Showkot 

and I also want to show that the email from example@example.com

+6
source share
4 answers

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

2) Try changing "From:" to "From: " . Or perhaps the $from variable does not matter.

+6
source

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

here is an example ..!

 $to = " sended@test.com "; $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 = " tester@test.com "; $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; mail($to,$subject,$message,$headers); 

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

+5
source
 $line = "\n"; $a = "Customer Phone: "; $b = "Customer Last Name: "; $message = $a.$number.$line.$b.$LastName; $to = " forgotten_tarek@yahoo.com "; $subject = "Umrah Booking"; $from = $mailer; $headers = "From: " . $from. "\r\n". 'Reply-To: '. $from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to,$subject,$message,$headers); 
+2
source

You can enter html in the message tag, for example:

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

Source: https://habr.com/ru/post/902179/


All Articles