I am having a problem sending emails when I add header information.
However when I just remove the header parameter it works. What is wrong? Is it the code? Or some setting I need to change on the web server admin panel to say "Allow-Headers" or something?
I am trying to send to hotmail in case this has any relavance in determining the problem.
Any help would be greatly appreciated. Thanks.
Below Doesn't Send Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message, $headers);
?>
Below Sends Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message);
?>
I use these headers in my php mailing function and it works well. Note: I also use a third party mail-routing service to avoid having my mails marked as coming from a spammy IP. You might want to look into that also.
$headers = 'From: '.$from.'#foo.net' . "\r\n" .
'Reply-To: '.$from.'#foo.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I also use the optional fifth parameter to mail() to set the envelope address, e.g.:
$parameters = '-f '.$from.'#foo.net';
so the final call is:
mail($to, $subject, $message, $headers, $parameters);
You can just delete the "FROM:" from the headers list .. it prevents it in some hosts .But the real question then will be how ca I change the sent from email address to a specific email that I want
Related
I read the other questions and solutions... which is why I'm frustrated. I didn't code this app, but I'm trying to retrofit it.
Currently it sends a confirmation email to the email address that gets entered by the customer in the field. When I comment out the mail($to,... part at the bottom, it breaks the confirmation email functionality, so I know I'm in the right place in the code.
I just want a duplicate email sent to my master email address. I thought if I just put another mail command under the functional one, but specified a static address instead of the $to var it would work... but it doesn't. I couldn't get the CC header functionality to work either based on other questions, so I thought just sending a duplicate email to another address would work just fine.
Here is the working code:
$sq2 = myQuery(" select * from admin ");
$dat2 = mysql_fetch_object($sq2);
$from = "reservations#duelingpianopiano.com";
$to = $email;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From: $from" . "\r\n";
$headers .= "Reply-To: $from" . "\r\n";
/*$headers = "From: $from" . "\r\n" .
"Reply-To: $from" . "\r\n" .
'X-Mailer: PHP/' . phpversion();*/
mail("vmvijitha#gmail.com", $subject, "sendemailtemplate($templateid,$tid,$userid,$modification)".$mailcontent, $headers);
//return;
mail($to, $subject, $mailcontent, $headers);
I feel like if I should just be able to add this line at the bottom to send the exact same email confirmation redundantly to my master email address for safe keeping.
mail("reservations#duelingpianopiano.com", $subject, $mailcontent, $headers);
Note: I think this line is an artifact from the original developer, and I can't tell whether it's working or not.
mail("vmvijitha#gmail.com", $subject,...
What am I assuming wrong?
insert multiple addresses using comma-separator in single variable.
$email_to = "xxx#one.com, xxx#two.com, xxx#three.com"
mail($email_to, $subject, $mailcontent, $headers);
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);
<?php
$to = 'abc#gmail.com';
$subject = 'the subject';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = file_get_contents('http://domain.com/newsletter.html');
$headers = 'From: xyz#gmail.com' . "\r\n" .
'Reply-To: xyz#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
This in my mail code. Here I am sending my newsletter to my existing customer.
Can anyone help me how can I send/open the newsletter as the page through mail ?
I suggest you use the following, yet you won't be able to use an http:// call, because this goes against security reasons.
By doing so, anyone could include whatever they want from whatever website. The file must reside on your server in order for the following to work.
Making use of the include(), ob_start() and ob_get_clean() functions.
You must use a relative path to the file you wish to include.
<?php
ob_start();
include 'file.xxx';
$message = ob_get_clean();
$to= 'email#example.com';
$subject = 'the subject';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: email#example.com' . "\r\n" .
'Reply-To: email#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){
echo "Message sent.";
}
else{
echo "There was a problem. Check your logs.";
}
?>
Footnotes:
I quote jsalonen from a comment: "Keep in mind that CSS support in email readers is (probably intentionally) very limited: campaignmonitor.com/css - so if it works in a regular browser, it may or may not work in an email reader."
Most Email clients such as Google will ignore CSS, so it's best to use inline CSS.
Images:
Another thing you will need to do is, if you are using images, then that's where you will need to use an http:// call to the image location(s).
I.e.: <img src="http://www.example.com/images/image_1.jpg">
if allow_url_fopen is available in the ini file, you can do this:
$html = file_get_contents('http://domain.com/newsletter.html');
$message = $html;
The reason this should work is because most email clients can read emails sent as HTML (as long as you're sending emails as HTML and not just plaintext emails).
You can use echo htmlspecialchars($html); to see what HTML you're sending.
I'm using iPage for my website, and I'm using a simple mail() method to send test mails from my page. On iPage, I have email capabilities via mark#domain.com. But when I send an email out, it comes from the iPage server and is sent from ipg.domain#boscustweb3506.eigbox.net, which is quite ugly looking!
Is there a way I can use the mail() method in php to send an email from my page that will use the shorter sender above? Thanks for any and all help!
you need to add a header named From. this code will send with the mail address webmaster#example.com:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Try this, You can add the From header to customise the sender address.
$from ='mark#domain.com';
$headers = 'From: ' . $from . "\r\n";
...
mail($to, $subject, $message, $headers);
I am using a simple HTML form for an event registration and I would like to send a PHP confirmation email to the registrant with the same information that is going to the administrator.
Here are the details:
$emailFromName = $_POST['name'];
$emailFrom = $_POST['email'];
$emailFromPhone = $_POST['phone'];
I would like to use the value from $emailFrom in the following email address to:
$emailTo = "name#domain.com", \"$emailFrom\";
edit: Added new configuration:
$emailHeaders = 'From: "Conference" <noreply#conference.org>' . 'CC: . $emailFrom .';
This obviously doesn't work, but you get the idea of what I am trying to.
Thanks!
You will need to add headers to the mail function...
for example:
$headers = 'From: Family History Conference <noreply#familyhistoryconference.org>' . "\r\n" .
'Reply-To: noreply#familyhistoryconference.org' . "\r\n" .
'CC: ' . $emailFrom . "\r\n";
and then
mail($to, $subject, $message, $headers);
References:
PHP Mail Function
You put "From: $name <$emailFrom>" in the additional parameters of the mail() function:
http://php.net/manual/en/function.mail.php
So, basically you want to CC a copy of the message to the user as well as the administrator?
It depends on which PHP library you're using to send it. If you're using the default PHP mail() function, you'll need to add additional headers:
// Additional headers
$headers .= 'Cc: ' . $emailFrom . "\r\n";
// Mail it
mail('admin#email.com', $subject, $message, $headers);