I am using below code to send email using php
<?php
$to = $_POST['emailbox'] ;
$message1 = nl2br($_REQUEST['output_textarea']);
$subject = 'script';
$message = "
<html>
<body>
<table bgcolor='Lavender' width='100%'>
<tr><td><font face=consolas>$message1</font></td></tr>
</table>
<br/><br/>
Hyperlink Code
</body>
</html>
";
$headers = "From: ase#abc.com\r\n";
$headers .= "Reply-To: anoop#abc.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
?>
But the hyper link mention in above code Hyperlink Code giving me below error:
Parse error: syntax error, unexpected T_STRING in eval()’d code on line 24
If I remove the the hyperlink line code from code, its working fine. how can I mention the hyperlink in email ?
Notice how the syntax highlighting breaks in your code? Notice that it happens when you use double quotes?
The simple answer is the change out:
Hyperlink Code
For:
Hyperlink Code
But you can also do:
$message = <<<_E_
<html>
<body>
<table bgcolor='Lavender' width='100%'>
<tr><td><font face=consolas>$message1</font></td></tr>
</table>
<br/><br/>
Hyperlink Code
</body>
</html>
_E_;
It's called Heredoc syntax.
I think that the double quotes ("") are making some noise ¿?
Maybe you can try single quotes (''), like:
<a href='http://www.hyperlinkcode.com'>Hyperlink Code</a>
Sorry if i'm wrong..
Related
I'm trying to send HTML email from my Custom Controller.
Here's code.
public function execute()
{
$to = "dev#test.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>'.$_POST["company_name"].'</td>
</tr>
</table>
</body>
</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: <webmaster#example.com>';
mail($to,$subject,$message,$headers);
How Can I use dynamic variables based on POST request so that Email Send perfectly with Dynamic form.
I've tried as I paste above code but still getting syntax erros in PHP Strom.
Any Help would be appreciated.
Instead of:
<td>'.$_POST["company_name"].'</td>
use:
<td>".$_POST['company_name']."</td>
Your HTML is quoted with double quotation so to return to PHP you also need to use double one.
Two things. For multiline strings, I'd recommend using heredoc. Secondly, save the form data into a variable before using it in the string.
$company_name = $_POST['company_name'];
$message = <<<EOD
<html>
<h1>$company_name</h1>
<html>
EOD;
What's the best way to construct and send an HTML email using mail()with bootstrap formatting?
I've tried the following example (not full code):
$msg = "
<html>
<head>
<link href = '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
</head>
<body>
<p>This is a request to reset your password</p>
<a href='blah'>Click here to reset your password.</a>
<button type='submit' class='btn btn-info btn-sm'>Reset</button>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1"."\r\n"; "X-Mailer: php".
$headers .= 'From: Password Reset <passwordreset#blah.co.uk>' . "\r\n";
The mail sends and is received in html but not formatted.
Unless you put all of the bootstrap code directly in your email, no. Email clients remove remote files by default to prevent user tracking. You cannot code around this.
When I send a really basic HTML email via a file using PHP mail it displays perfectly for me. But for my client he sees all the HTML tags in the email.
I have my own dedicated server, to try to problemsolve I ran the exact same file from a Heart Internet shared server I have and the email displayed perfectly to my client (no HTML tags) so it points to something to do with the server.
<?php
$to = 'tom#myemailaddress.com';
$subject = 'TOM Testing: HTML displaying correctly?';
$message = '
<html>
<head>
<title>This is a test</title>
</head>
<body>
<p>To see if</p>
<table>
<tr>
<th>You</th><th>See</th><th>The</th><th>HTML</th>
</tr>
<tr>
<td>or</td><td>it</td><td>is</td><td>formatted</td>
</tr>
<tr>
<td>correctrly</td><td>1</td><td>2</td><td>abc</td>
</tr>
</table>
</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";
// Mail it
mail($to, $subject, $message, $headers);
?>
Here is my php info: http://www.saloponline.co.uk/phpinfo.php
i am trying to send html image mailer using php mail function on linux platform. There is one issue when i am trying to send simple html content then it successfully get delivered to its subscriber. but when i try to send emailer which contains few images then it fails to deliver it. below are two codes 1 by which simple html is delivered. 2 which is not getting delivered.
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
code 2:
<?php
//change this to your email.
$to = "abhinav#xyz.in";
$from = "abhinav.1#gmail.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message= <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
* maaking.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
I corrected the code by which I am able to send image mailer below is the code:
<?php
$to= 'abhinav#xyz.com' . ',';
$to .= 'abhinav#gmail.com';
$sub='test1';
$msg= <<<EOF
<html>
<body>
<table>
<tr>
<td><img src="http://d32vlg867bsa1v.cloudfront.net/z/prod/w/2/i/zovi-logo2.png" />
</td>
</tr>
</table>
</body>
</html>
EOF;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: <centos_test#example.com>' . "\r\n";
mail($to,$sub,$msg,$headers);
?>
I am still working to sent highly customized mailer and will describe how it can once I found how it can be done.
my php email script doesn't seem to be sending but I can't see why. Also I understand that there are certain security flaws with my script, any advice with that is much appreciated!
thank you
<?php
include('config.php');
$email1 = $_POST['email1'];
$id = $_POST['id'];
$fname = $_POST['fname'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$to = '$email1';
$from = "$email";
$subject = "SC - You Have a Reply";
$body = "<html>
<body bgcolor=\"#FFFFFF\">
<center>
<b>Dear $firstname</b> <br>
<font color=\"red\">You have a response, regarding your Ad on StudentClutter!</font> <br>
<p> --------------------------------------------------------- </p>
<b> $fname </b>
<p> --------------------------------------------------------- </p>
<p> ".stripslashes($_POST['body'])." </p>
<br>
<br>
<br>
<p> You can reply to them by email: $emailadd </p>
<br>
<br>
<br>
<p>Thank you for using studentclutter.com </p>
<p> -- The Student Clutter Team </p>
</center>
</body>
</html>";
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
// now lets send the email.
mail($to, $subject, $body, $headers);
echo "Message has been sent!";
?>
You are using single quotes around $email1, these are not necessary. Remove the quotes and it should work just fine.
Like this
$to = $email1;
I would advise you to check out the PHPMailer class, this class offers a whole range of features, along with security. It is very easy to use, just read through the documentation.
UPDATE
You have not escaped the return and new line special characters at the end of some of the headers. Change the end of the lines to look like this:
\r\n";