How we can a Send PHP email to gmail archive - php

How we can a Send a email using PHP mail function to gmail archive mail folder?
My code
$to = "myemail#gmail.com";
$subject = "Subject" ;
$message = 'Example message with <b>html</b>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: xxx <xxx>' . "\r\n";
mail($to,$subject,$message,$headers);
Note:
Smile email/mail function is fully functional but I want to send mail to gmail archive folder directly.Is there any way to do that?

It depends on the recipient's e-mail settings, you can't do that on the sender side.

Related

Personalised 'To' field when sending large email list using PHP mail and multiple addresses in the Bcc

Im trying to remember a trick i was taught a while back but can not.
Basically, im using PHP mail() in this fashion:
$to = "emailAddress1#domain.com";
$subject = "Welcome to BuildSanctuary";
$messageContent = "Thankyou for registering Bla bla bla";
$message = 'SOME HTML EMAIL STUFF including the $messageContent var';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Accounts<accounts#domain.com>' . "\r\n";
$headers .= 'Bcc: emailAddress1#domain.com,emailAddress2#domain.com,emailAddress3#domain.com,emailAddress4#domain.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
I got told a while back that there was a way that you could put your own email in the to field, but when the users receive the emails it looks like they were personally sent the email and the to field shows just their email.
Is this possible? Cant think how.
Thanks.

php mail function with customizes from value

Why does this send emails?
$from_admin = $_POST[EMAIL];
$message_admin = 'some html...';
mail($to_admin,"subject",$message_admin,"FROM:$from_admin");
This email looks like it came from my gmail account.
While this doesn't send the email.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . $to . "\r\n";
$headers .= 'From: Registration <register#myserver.org>' . "\r\n";
mail($to, $subject, $message, $headers);
When I contacted my hosting support, they said that I need to do SMTP authentication. But, then why does the first mail function work? I would be ok if its not actually using that server, but people can reply the the html email and still reach the correct account. Is there any way around this?

Configuring exim's outgoing e-mail address

I forgot how I set it. I have two websites and I send the e-mail through my second site. Here's my /etc/exim4/passwd.client file:
*.google.com:noreplyn#firstsite.com:password
*.google.com:noreply#secondsite.com:password
I'm sending mail through PHP's mail() function with the following headers:
$headers = 'From: no-reply <noreply#secondsite.com>' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Reply-To: noreply#secondsite.com' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
But I am getting this header on my client's email:
from: no-reply firstsite.com
reply-to: secondsite.com
to: apathetic012#gmail.com
How do I properly set a custom outgoing e-mail address for exim?
PS: I'm using a smarthost (Google apps)
Set your envelope From.
mail($recipient, $subject, $body, $headers, '-f noreply#secondsite.com');

PHP mail function is sending emails in Gmail's SPAM folder, How to get rid of it?

i am using this code :
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
it sends email to my gmail's SPAM folder .
Suggest any solution .
i dont want to use any PEAR MAIL type way to send email or dont want to require and include any file.
This functions works without including/requiring any additional php file.
You should use proper header like this from PHP manual
$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);
The Gmail spam filter has lots of parts to it which determine the spamminess of mail. You could start by seeing the SPF record for your domain. Avoid using sales language, HTML and colours where possible in your email.
There's also an old but fun video from Google about how their spam filtering works.
It's all in the headers. I don't know how GMail works internally, but I've found on my projects that setting Reply-To can Content-Type headers seems to fix this.
See PHP mail() docs for an example of doing this.
(Note: I've got a PHP questionnaire/response system that sets these headers and the e-mails come through correctly to GMail, Hotmail and Yahoo! Mail).

Getting a CC copy of user invite Emails

The code below works great. It allows a user to send a recommendation for my site to a list of friends via email.
For each person that gets the email below, I would like to get an email with that person's email, and the name of the person that sent them the message. If my email address was john#site.com, what code could I use to do this?
Thanks in advance,
John
$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "CC: foo#example.com\r\n";
$headers .= "BCC: foo#example.com\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
Rather than messing about with raw headers, consider using one of the many great APIs available, like Swiftmailer, PHPMailer, or Zend_Mail to name just three. Zend_Mail example:
$mail = new Zend_Mail();
$mail->setBodyHtml('<p>hello</p>');
$mail->setFrom('foo#example.com', 'foo#example.com');
$mail->setSubject('Test Subject');
$mail->addTo('foo#example.com', 'Test');
$mail->addCc('foo#example.com', 'Another Test');
$mail->addBcc('foo#example.com', 'Another Test');
$mail->send();

Categories