Good morning,
I want to remove the gmail warning 'gmail couln't verify that ...#... sent this message' when I send email with php.
I know it is because I use the email function php that don't have authentification so I try PHPMailer and PHP pear but the page turn and turn until the infinite and nothing is happened.
My host is 1&1.
I try with gmail instead smtp and account instead of 1&1 but same result.
<?php
// Pear Mail Library
require_once "Mail.php";
$from = '<***#motelavigna.co>'; //change this to your email address
$to = '<***#gmail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'auth.smtp.1and1.fr',
'port' => '465',
'auth' => true,
'username' => '***#***.co', //co is not an error
'password' => '***' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
?>
thanks.
I came across this issue recently too and realised the problem is not from the PHP script, as I first thought, but from not having an SPF record for the domain name.
An SPF record identifies which mail servers are permitted to send emails from a particular domain name. If the domain doesn't have an SPF record then Gmail can't verify that the email came from the right place.
Coincidentally I'm also with 1&1, so see here for how to set up SPF records for 1&1. The value you need to use is:
v=spf1 include:_spf.perfora.net include:_spf.kundenserver.de -all
You can also check if the email passed the SPF test by clicking the arrow at the top of the email in Gmail, and pressing 'Show original'.
Related
I am completely new to php. I am trying to send an authenticated email using PHP Pear Email system. Whenever I send email using gmail smtp I get following error
Fatal error: Call to undefined function parseAddressList() in C:\wamp\bin\php\php5.4.16\pear\Mail.php on line 255
Here is the code of my application
<!--
Sending an email using gmail smtp server, with authentication, ssl version
eMail With Authentication SSL Version
-->
<?php
// Pear Mail Library
require_once "Mail.php";
require_once "Mail/RFC822.php";
$from = 'me1#gmail.com';
$to = 'me2#hotmail.com';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'me1#gmail.com',
'password' => 'password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
?>
Can anybody give suggestions on how I can send authenticated email through gmail, using PHP Pear mail package? Thanks in Advance.
My Problem is resolved. Thanks for your direction.
I actually made a mistake in Mail.php file. Accroding to another stackoverflow post PHP: PEAR mail help
I pasted the below text in Mail.php
$Mail_RFC822 = new Mail_RFC822();
$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);
But some how - was missing so the above lines became
$Mail_RFC822 = new Mail_RFC822();
$addresses = $Mail_RFC822>parseAddressList($recipients, 'localhost', false);
which was the cause of bug.
Now I have corrected that and is able to send the emails.
Thanks a lot.
I have google apps setup for one of my site's emails, thus making the site's built-in email routing useless when doing things from the web. What i need to do , is have it use ssl/smtp to connect to the google apps setup.
To accomplish this, I've used PEAR Mail and mime (for the HTML contents).
The messages get sent without an issue... the ONLY problem i'm having, is that the 'From' header isn't being saved across transmission. Instead, the account email is in the 'from' header.
The accounts exist on the webserver's end (which means nothing since its all going through google), and i've added aliases to my gmail apps administration end. But no matter what i do, its not changing the 'from'.
Is this just something i'm going to run into when using a single account with google apps' gmail? (--forced 'from' from the account name?)
Thanks
--for those who were wondering, here is an example function for the mail sending:
function pearMail($from, $fromTitle, $to, $subject, $text, $html)
{
require_once "Mail.php";
require_once('Mail/mime.php');
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "name#domain.com";
$password = "PASSWORD";
$headers = array ('From' => $from,
'Return-Path' => '-do not reply-',
'To' => $to,
'Subject' => $subject);
$crlf = "\n";
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers,true);
// Sending the email
$mail =& Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
See the google help on changing From::
The custom 'From:' feature works only if you already own the account linked to the alternate address. To send mail with a different Gmail username, you must first sign up for that address.
The problem I am facing at the moment is really odd.
I've used the script given below before and it has worked like a charm, but now it is simply not working.
Here is the code:
function send($str){
$from = "body<body#gmail.com>";
$to = "TargetName <matthew.s#gmail.com>";
$subject = "Questionnaire Submission!";
$body = $str;
$host = "smtp.gmail.com";
$username = "body";
$password = "pwd";
$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("An error occured during submission! Please try again!");
} else {
echo("Submission Successful!!\nYou will now be redirected to a page to fix the timings.");
}
}
Now this code wont send the mail can I cannot understand why.
Some help would be appreciated.
Best Regards
Priyabrata
edit
I received a mail from the account I was using to send the mail :
This is an automatically generated Delivery Status Notification
THIS IS A WARNING MESSAGE ONLY.
YOU DO NOT NEED TO RESEND YOUR MESSAGE.
Delivery to the following recipient has been delayed:
Message will be retried for 2 more day(s)
Technical details of temporary failure:
Message temporarily rejected. See http://support.google.com/mail/bin/answer.py?answer=69585 for more information.
This has nothing to do with PEAR mail; it's a general email issue.
PEAR's Mail package can send mails fine - also with recent PHP versions like 5.5 and 5.6beta1.
Try to send the mail to a different email address, this might work.
Also follow Gmail's guidelines as depicted in the support URL in your response.
In situations where the recipient is a Gmail user, we will include:
...
So send the mail to a gmail address, and you will get more information.
FIrst of all I don't intend to spam - I 'm building email facility in my application and would like to be able to include any email address in the from header of the email while be able to send it from any mail server i.e like show a yahoo address in the email from field while send it from my own smtp server? Is it possible? I'm using php and zend framework here
Zend_Mail allows you to specify all that.
Setting up transport (during bootstrap):
$tr = new Zend_Mail_Transport_Smtp($mail_smtp_host, array(
'auth' => 'login',
'username' => $mail_smtp_username,
'password' => $mail_smtp_password,
'port' => $mail_smtp_host_port,
));
Zend_Mail::setDefaultTransport($tr);
Sending a message anywhere in your app:
$mail = new Zend_Mail();
$mail->setFrom($email_from, $email_from_name)
->addTo($email_to)
->addCc($email_cc)
->addBcc($email_bcc)
->setSubject($email_subject)
->setBodyHtml($email_html)
->setBodyText($email_text)
->send()
;
The following works with sendmail and should work with sendmail-like smtp servers. If the from domain does not match the domain of the originating server, the chance of being flagged as spam increases.
$msg = 'my message body';
$subject = 'my message';
$to = 'email#example.com';
$from = "ali#yahoo.com";
$headers .= "From: $from\r\n";
$flags = '-f "$from"';
mail($to, $subject, $msg, $headers, $flags);
You can send through Yahoo's SMTP server.
smtp.mail.yahoo.com, SSL, port 465, username/password for the Yahoo address.
First off, the server: Exchange 2003 sp2 running on Windows 2003 Server sp2
I have a script that sends email to two email accounts, one called students# and the other being fs# (faculty/staff). We are setting both those email accounts to only accept incoming email by authenticated users on the exchange server, to spare ourselves from spam/junk mail. So right now the emails being sent by the script are not successful. I have the return-path email as a legit user, but it is not authenticated. I noticed that when I tried sending a test via my mail client (Apple's Mail.app) and since I use email through their IMAP server and not through exchange, my email failed as well.
Here is the code for sending the email:
$mail = new htmlMimeMail();
$message = $today.$announcements.$food.$upcoming;
$mail->setHTML($message);
$mail->setSubject($subject);
$mail->setSMTPParams('mail.domain.com', 25, true, 'user', 'pass');
$mail->setFrom("no-reply#domain.com");
$mail->setReturnPath("webmaster#domain.com");
if($message)
$mailresult = $mail->send(array($emailto));
I have never authenticated with an exchange server using the HTML Mime Mail for PHP (http://www.phpguru.org/static/mime.mail.html) class before. Any help would be appreciated.
Maybe there is another PHP class that easily allows authentication with an Exchange server?
EDIT: Are there any php mail classes out there that authenticate properly with an exchange server?
Another EDIT: The Exchange Server uses NTLM authentication and uses Active directory. Hope this helps.
Exchange supports the standard SMTP Auth mechanism, so I would use that. Here is an example using Pear::Mail from here.
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender#example.com>";
$to = "Ramona Recipient <recipient#example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_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>");
}
?>