The below code is designed to send an email when a sale has been made. The body of the email contains information like the customers name, their email address etc. All I'd like to do is add a line break to each of the fields within the final output of the email. I've tried a simple HTML line break and /n and /r which didnt work....any ideas? Thanks!
<?php
//Enter email to receive purchase alerts
///////////////////////////////////////////
$alert_email = 'sales#my-domain.com';
///////////////////////////////////////////
$username = $_POST['username'];
$password = $_POST['password'];
$to = $alert_email;
$subject = 'Sale! = ' .$course;
$message = $name. ' '. $email. ' '. $username. ' '. $password;
$headers = 'From: sales#my-domain.com' . "\r\n" .
'Reply-To: hi#my-domain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
The line that needs to be changed I am sure is this one (and line breaks inserted somewhere here:
$message = $name. ' '. $email. ' '. $username. ' '. $password;
Thanks!
Send a HTML content by applying header Content-type:text/html
$to = $alert_email;
$subject = 'Sale! = ' .$course;
// 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: <sales#my-domain.com>' . "\r\n";
$headers .= 'Reply-To: hi#my-domain.com' . "\r\n";
$message = $name. '<br /> '. $email. '<br /> '. $username. '<br /> '. $password;
mail($to, $subject, $message, $headers);
\n should work. Be sure to use a \ instead of a forward slash.
Related
I¨ve got a problem answering mails sent from my website, as the senders emailaddress isn´t showing anywhere, only the webmasters email
Here is my code:
<?php>
$from="kim.s.nielsen#mail.dk";
$email="info#intotext.dk";
$name=$_POST['name'];
$message=$_POST['message'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $fromName . ' <' . $fromEmail .'>' . " \r\n" . 'Reply-To: '. $fromEmail . "\r\n" . mail($email, $name, $message, $headers);
print"Din besked er sendt. Vi vender tilbage så hurtigt som muligt." ?>
Use this format to send your email, this will show the senders email address, try this. you have concatenated the mail function with your header, mail() is not header it is used to send your email.
$fullname = "full name";
$from = "sender#mail";
$to = "reciever#mail";
$subject = "Your subject";
$message = "<h1> heading </h1><p> Message </p>";
$headers = [
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1',
'From: ' . htmlspecialchars($fullname) . " <$from>",
'X-Mailer: PHP/' . phpversion()
];
mail($to,
htmlspecialchars($subject),
nl2br(htmlspecialchars($message)),
implode("\r\n", $headers)
);
I'm getting the 500 Internal Server Error. I called goDaddy and they told me it's not something on their end. I also don't have a .htaccess file. I checked the contact page and checked spelling it is calling the right .php file.
This code was working perfectly. I tried to change something it didn't work. I tried going back to the original code and now that doesn't work either. I don't have a backup. I commented out line by line to pin-point the problem if I erase the mail($to, $subject, $message, $headers); part I don't get an error but obviously don't receive anything. Here is the website if that helps to inspect.
http://www.crownjewelre.com/contacts.html
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$comments = $_POST['comments'];
// multiple recipients
$to = 'michaelgaraysi#yahoo.com' . ', '; // note the comma
// subject
$subject.= "CrownJewelRe question From: ".$first_name." ".$last_name. "\n";
// message
$message = "
<html>
<head>
<title>Contact Information</title>
</head>
<body>
<table>
<tr>
<td>Name: </td><th>".$first_name."</th><th>".$last_name."</th>
</tr>
<tr>
<td>Email: </td><th>".$email."</th>
</tr>
<tr>
<td>Telephone: </td><th>".$telephone."</th>
</tr>
</table>
<br><br>
<p>Comments: <strong>".$comments."</strong></th>
</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);
?>
like the others $subject.= is auto-expand of a non existing var but that not the problem here :)
1st : have you tested a blank page with only the function mail :
mail ('michaelgaraysi#yahoo.com','test','message corpus');
if its working its not a missconfig of youre PHP.
2nd : How can you use in 2015 the mail function, its have a high spam rate, instead use https://github.com/PHPMailer/PHPMailer or other.
I think it will solve your problem or maybe you just need to remove the "\n"; on $subject :)
try to change,
$to = 'michaelgaraysi#yahoo.com' . ', ';
to
$to = 'michaelgaraysi#yahoo.com';
and
$subject.= "CrownJewelRe question From: ".$first_name." ".$last_name. "\n";
to
$subject= "CrownJewelRe question From: ".$first_name." ".$last_name. "\n";
and finally, try to run this simple php mailer script, and then apply your changes,
<?php
$to = 'michaelgaraysi#yahoo.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: birthday#example.com' . "\r\n" .
'Reply-To: birthday#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I would like to use <<< to send html email in php. So far i remember it works great previously but not working right now.
//ALL HTML MUST BE LEFT ALLIGNED.
$php_var="variable value";
$body = <<<EmailBody
<html>
<body>
$php_var
</body>
</html>
EmailBody; //EmailBody will not show in Email.
$headers = 'From: info#mydomain.com' . "\r\n" .
'Reply-To: info#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject="Test HTML Email";
$body="test email from mydomain";
$to="aminulsumon#gmail.com";
mail($to,$subject,$body,$headers); //$header type should be html
any help is highly appreciated.
There should NOT be anything before AND/or after EmailBody;; it being the closing identifier.
Read the documentation on heredoc
Use this:
//ALL HTML MUST BE LEFT ALLIGNED.
$php_var="variable value";
$body = <<<EmailBody
<html>
<body>
$php_var
</body>
</html>
EmailBody;
$headers = 'From: info#mydomain.com' . "\r\n" .
'Reply-To: info#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject="Test HTML Email";
$body="test email from mydomain";
$to="aminulsumon#gmail.com";
mail($to,$subject,$body,$headers); //$header type should be html
Having something (space, text, etc.) after the closing identifier, will result in the following error:
Parse error: syntax error, unexpected end of file in....(path to file) on line X
had error reporting been set
http://php.net/manual/en/function.error-reporting.php
Add this just before your opening <?php tag:
error_reporting(E_ALL);
ini_set('display_errors', 1);
Remove the comment on the end of:
EmailBody; //EmailBody will not show in Email.
So it is only:
EmailBody;
Also you define $body twice, so take out:
$body="test email from mydomain";
Here is one basic example to send html in email -
$to = 'abcd#gmail.com';
$from = "sender#gmail.com"; // sender
$subject = "Test email";
$message = '<html><body>';
$message .= "<p>This is The Email Address</p><br><span class='nonLink'>responder#example.com</span>";
$message .= '<br/>click here to complete your registration';
$message .= '</body></html>';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
// Additional headers
$headers .= "From: <$from>" . "\r\n";
// Mail it
if (mail($to, $subject, $message, $headers)){
echo "email sent successfully";
}
I have such code for send email:
$email = $_POST['message_email'];
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
before that I check whether the email is correct so it has to be.
Then I send an email:
$sent = wp_mail($newTo, $subject, $companyName . "\n" . $email . "\n" . $phoneNumber . "\n" . strip_tags($message) . "\n" . $outputMail, $headers);
and it doesn't work. I've tried change headers to:
$headers = 'From: My Name <myname#mydomain.com>' . "\r\n\\";
and then it works. Why my code does't work? I need to provide that email retreived from form.
Try like this:
****Ive edited the code****
$from = "your#mail.com";
$to = "to#mail.com";
$message = "Message";
$subject = 'subject';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
if(mail($from, $subject, $message, $headers)){
//success
}else{
//error
}
I would like to mail some text as bold in my email content. I have used the following code
$to = 'some#gmail.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$from = $param['email']; // this is the sender's Email address
$headers = "From:" . $from;
$name = $param['name'];
$subject = "Test";
$message = "message.\n\n"
."<b>Name:</b> ".$name . "\n\n"
."Adress: \n"
.$param['address'] . "\n"
.$param['zip'] . ", "
.$param['postal_area'] . "\n\n"
."E-post: ".$param['email'] . "\n\n\n"
mail($to,$subject,$message,$headers);
I have used <strong> also instead of <b> tag, but nothing works.
I get mail in the below format :
<b>Namn:</b> some name
Adress:
Borås, Sweden
4837, Boras
E-post: somemail#gmail.com
You are overwriting the header variable again. You need to append to it.
$headers .= "From:" . $from; //You forgot to concatenate here...
// ---^ //Add the .
Try setting the font weight property in a span:
$message = "E-post: <span style='font-weight:strong;'>".$param['email']."</span>";
But also see other reply, you are overwriting the header so it is not reading the message as HTML.