Generate email to file without sending - php

I want to generate an email using the mail() function:
<?php
$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();
// instead of sending mail, out put to file
mail($to, $subject, $message, $headers);
?>
But instead of having it actually send the email, I want it to output the email to file with all of the headers etc. as a mail server would see it.

With SwiftMailer you can use plugin: http://swiftmailer.org/wikidocs/v3/plugindev/sendevent

We use the Zend_Mail library and have different transports for destination (SMTP, STDOUT, file, etc.). Just in case that's an option, here's some information on Zend_Mail transports.

Related

Message containing bare lf's

I have a problem with sending mail from PHP.
$to = 'admin#****';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#****' . "\r\n".
'Reply-To: webmaster#****' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers)
When I run this simple example script, or basically any tutorial script, I get the following error from hMailServer 554 Rejected - Message containing bare lf's.
I know this is due to a setting in hMailServer, but I don't want to turn off the RFC compliance check, I want to send correctly formatted mails.
Can you help me figure out what's wrong?

mail() method using PHP, how do I set the sender?

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);

Sending Email in PHP from a button

Let me start by saying I do not have a lot of programming knowledge. I use a program called PHPRunner to generate most of the php that I do. It is mainly for small office stuff nothing fancy.
My question is:
I have a table that has 6 fields one of them called email. When I go into a record I wanted to put a button called "send notification" that would email the record details to the email address associated with that record.
Any help would be greatly appreciated. I know it is probably out here on the web, possibly searching the wrong way.
You can use the mail function in php. Example from the provided link:
<?php
$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);
?>
For sending email using PHP, use mail() function
http://php.net/manual/en/function.mail.php
Example:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$from = 'webmaster#example.com';
$headers = 'From: '.$from . "\r\n" .
'Reply-To: '.$from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

PHP mail function, remove the neccessity for errors-to header

I'm on a server that requires the errrors-to header to be set when using PHP mail() function. Popular applications such as Wordpress don't specify this header (at least not everywhere) - so the email isn't sent (instead I'm sent a message saying there was an error sending the email because it lacked the header). The server host says this is not something they can change for the system. I do not have access to the .ini file. Is there something I can do about it?
yes, by setting the mail-header you need with the normal mail()-function:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'errors-to: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
In wordpress, you can overload the wp_mail()-function to include that header.

how to send email where "from" having 'firstname'<space>'lastname'<email_id> in php

i have to send email where email "from" having 'firstname''lastname'.
For ex: first_name="john"
last_name="Dime"
email_id="john#john.com"
then from should be like this in the sent mail: From: john dime.
Please help me if u find any solution.
As per RFC 2822, you simply need to set a header of the form...
From: John Dime <john#john.com>
...in the headers portion of your email.
I have found instances of mail not being delivered correctly if the from address is not specified using the -f option with sendmail:
<?php mail($email, $subject, $body, $headers, "-f $email") ?>
Yes simply write your name in "FROM" portion like given below
$headers = 'From: Fname Lname<webmaster#example.com>' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
This is taken from php.net website:
<?php
$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);
?>
You can specify the from field in the additional headers.
You just need to change the webmaster#example.com with the desired string
http://php.net/manual/en/function.mail.php - this can be useful for you

Categories