My code
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= 'From: Me <me@gmail.com>' . PHP_EOL;
imap_mail('you@gmail.com','test',"$output","$headers");
Is there a way to sign the mail? when I use above code to test sending emails, I receive the email but I am getting the error
This message may not have been sent by: me@gmail.com Learn more Report phishing
according to gmail they attach signed data to the headers to authenticate
I am using gmail imap to send the mails
$inbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
Is there a way to authenticate the email using php imap?
If you want to send mails as a Gmail user I recommend using the Gmail's SMTP. As IMAP is mainly used to receive mails from the inbox.
Here's how to send mails from Gmail's SMTP.
First
- Make sure the PEAR Mail package is installed.
- Typically, in particular with PHP 4 or later, this will have already
been done for you. Just give it a try. (Mail.php)
Then
Sending Mail from PHP Using SMTP Authentication - Example
<?php
require_once "Mail.php";
$from = "Sender <sender@gmail.com>";
$to = "Recipient <recipient@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.gmail.com";
$username = "username@gmail.com";
$password = "Gmail Password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example
<?php
require_once "Mail.php";
$from = "Sender <sender@gmail.com>";
$to = "Recipient <recipient@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "username@gmail.com";
$password = "Gmail Password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Source about.com