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);
?>
Related
My problem begins when I had to add a single landing page to an existing Drupal website. I've never worked with this CMS, so I just created a folder for this page in the root folder and put all the content there.
Then it appeared that I need to send mail from this page after submitting a form there. As I understood I can't use drupal_mail() function there, so I tried something like that:
$to = $email;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
But that gave me no result.
Then I installed SMTP auth module for Drupal and tried to send mail, but again I had no result. However, test messages from SMTP module have been sent correctly.
<?php
$to = $email;
$subject = 'the subject';
$message = 'hello';
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\n";
$headers .= "From: $email" . "\n";
$headers .= "Reply-To:: $email" . "\n";
mail($to, $subject, $message, $headers);
?>
Some hosts require you to use an additional parameter, -f, to send mail.
Try:
mail($to, $subject, $message, $headers, "-f".$email);
I brought a shared sever, and got a little storage space. When i run my web site, the mail function works perfectly. Mail has been sent with subject and message to all receivers. But the mail which is sent mentioned "From : ". Headers what i included are not working.
I want to send with my headers Eg:Form: mymail#mysite.com . How can i do it?
<?php
$output="";
if(isset($_POST['submit']) && !empty($_POST['message']))
{
$sub=$_POST['subject'];
$msg=$_POST['message'];
$sql = "select email from login where status='client'";
$query = mysqli_query($con,$sql);
$to=array();
while($row = mysqli_fetch_array($query))
{
$to[] = $row['email'];
$parts = implode(',',$to);
$headers = 'From: mymail#mysiet.com;';
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$subject = $sub;
$content = $msg;
}
if(mail($parts,$subject,$content,$headers))
{
$output="mail sent";
}
else
{
$output="Error in connection, Mail could not be sent. Please try again";
}
}
?>
You need to manually specify the headers, this is the function I use and it delivers to pretty much every provider beautifully. The headers you want are From: and Reply-To: and I also advise the X-Mailer follows what is seen here, I found it years ago via SO as well.
<?php
$to = "user#anotherdomain.com";
$headers = 'From: My Name <email#domain.com.au>' . "\r\n" .
'Reply-To: My Name <email2#domain.com.au>' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'Content-type: text/html; charset=iso-8859-1';
$subject = "My subject line here";
$message = 'Message HTML and Content Here.';
if(mail($to, $subject, $message, $headers)){
// Success Here
}else{
// Failed Here
}
?>
I am not 100% certain it will work for you as I am on a dedicated machine, having said that - I do use it on multiple domains and have never messed with my Apache or php configuration in relation to mail settings.
Read More about the Mail function in PHP: http://php.net/manual/en/function.mail.php
You can try below code, just ripped from php.net
// 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";
Off topic but good to use PHPMailer.
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";
}
<?php
// multiple recipients
$to = 'ali.dzinemedia#gmail.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '<html>
<head></head>
<body>Content here and this is a link</body>
</html>';
// To send HTML mail, the Content-type header must be set
// Additional headers
$headers = 'To: Mary <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
echo "To : ".$to;
// Mail it
mail($to, $subject, $message, $headers);
?>
please solved this . when i added Download in the mail body mail not send.
if i remove this a tag mail sent and all other content display as per my requirement .
I dont know where is the exact problem, i m using godady hosting with PHP 5.3 version.
if any one have better solutions please share with me .
I've adjusted your code a little bit. Main change is in From: header - $header = "From: \"HCS Support Team\" <$from_id>\r\n" . "Reply-To: $from_id\r\n";
$erm.= '<TR>
<TD WIDTH="50%">' . "Download-" . $j . '</TD>
<TD WIDTH="50%">Download</TD>
</TR>';
$from_id = "support#xyz.com";
$header = "From: \"HCS Support Team\" <$from_id>\r\n" . "Reply-To: $from_id\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$subject = "Request for Case Study Solution Received";
#mail("ali.dzinemedia#gmail.com", $subject, $erm, $header);
It seems the mail is being sent, but it goes straight to SPAM folder. Please read about spam rules which make the mails go to spam folder: http://spamassassin.apache.org/tests_3_3_x.html
In your case the main problem with gmail is probably it's being sent with standard PHP mail function. Please try PHPMailer or PEAR::Mail.
The rules which are met by spamassasin in your mail are:
HTML_MESSAGE
HTML_MIME_NO_HTML_TAG
MIME_HTML_ONLY
How can I send an HTML-formatted email with pictures using PHP?
I want to have a page with some settings and HTML output which is sent via email to an address. What should I do?
The main problem is to attach files. How can I do that?
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob#example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
You need to code your HTML content using the absolute path for images. By absolute path, I mean you have to upload the images to a server and in the src attribute of images you have to give the direct path, like this <img src="http://yourdomain.com/images/example.jpg">.
Below is the PHP code for your reference: It’s taken from mail:
<?php
// Multiple recipients
$to = 'aidan#example.com' . ', '; // Note the comma
$to .= 'wez#example.com';
// Subject
$subject = 'Birthday Reminders for August';
// Message
$message = '
<p>Here are the birthdays upcoming in August!</p>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\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";
// Mail it
mail($to, $subject, $message, $headers);
?>
I have this code and it will run perfectly for my site:
public function forgotpassword($pass, $name, $to)
{
$body = "<table width=100% border=0><tr><td>";
$body .= "<img width=200 src='";
$body .= $this->imageUrl();
$body .= "'></img></td><td style=position:absolute;left:350;top:60;><h2><font color = #346699>PMS Pvt Ltd.</font><h2></td></tr>";
$body .= '<tr><td colspan=2><br/><br/><br/><strong>Dear '.$name.',</strong></td></tr>';
$body .= '<tr><td colspan=2><br/><font size=3>As per Your request we send Your Password.</font><br/><br/>Password is : <b>'.$pass.'</b></td></tr>';
$body .= '<tr><td colspan=2><br/>If you have any questions, please feel free to contact us at:<br/>support#pms.com</td></tr>';
$body .= '<tr><td colspan=2><br/><br/>Best regards,<br>The PMS Team.</td></tr></table>';
$subject = "Forgot Password";
$this->sendmail($body, $to, $subject);
}
Mail function
function sendmail($body, $to, $subject)
{
//require_once 'init.php';
$from = 'testing#gmail.com';
$headersfrom = '';
$headersfrom .= 'MIME-Version: 1.0' . "\r\n";
$headersfrom .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersfrom .= 'From: ' . $from . ' ' . "\r\n";
mail($to, $subject, $body, $headersfrom);
}
The image URL function is used for if you want to change the image. You have to it change in only one function. I have many mail functions, like for forgot password or create user. Therefore I am using the image URL function. You can directly set the path.
function imageUrl()
{
return "http://" . $_SERVER['SERVER_NAME'] . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/") + 1) . "images/capacity.jpg";
}
Sending an HTML email is not much different from sending normal emails using PHP. What is necessary to add is the content type along the header parameter of the PHP mail() function. Here is an example.
<?php
$to = "toEmail#domain.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>A table as email</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Fname</td>
<td>Sname</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\b";
$headers .= 'From: name' . "\r\n";
mail($to, $subject, $message, $headers);
?>
You can also check here for more detailed explanations by W3Schools.
You can easily send the email with HTML content via PHP. Use the following script.
<?php
$to = 'user#example.com';
$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" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: CodexWorld<info#codexworld.com>' . "\r\n";
$headers .= 'Cc: welcome#example.com' . "\r\n";
$headers .= 'Bcc: welcome2#example.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Source code and live demo can be found from here - Send Beautiful HTML Email using PHP
The simplest way is probably to just use Zend Framework or any of the other frameworks like CakePHP or Symfony.
You can do it with the standard mail function too, but you'll need a bit more knowledge on how to attach pictures.
Alternatively, just host the images on a server instead of attaching them. Sending HTML mail is documented in the mail() function documentation.
Use PHPMailer.
To send HTML mail, you have to set $mail->isHTML() only, and you can set your body with HTML tags.
Here is a well written tutorial:
How to send mail using PHP
The trick is to know the content id of the image MIME part when building the HTML body part.
It boils down to making the img tag—<img src="cid:entercontentidhere" />
Kronolith.php
Look at the function buildMimeMessage for a working example.