Ok I have a code to send emails. I'm using Swiftmailer and the transporter is sendmail. Here is the main code:
$transport = \Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -t -i');
$message = \Swift_Message::newInstance()
->setSubject('Notificatio')
->setFrom(array(BR_EMAIL => 'BR'))
->setTo(array($user->getEmail() => $user->getFirstName().' '.$user->getLastName()))
->setBody($msg, 'text/html', 'utf-8');
$headers = $message->getHeaders();
$headers->addIdHeader('Message-ID', time().'.'.uniqid('noreply').'#'.$_SERVER['SERVER_NAME']);
$headers->addTextHeader('X-Mailer', 'PHP v'.phpversion());
if(!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}
Now here is the strange part. If the recipient is a Gmail user, the email never gets to it. The send method doesn't give any failures, but the email is lost. It's not in the spam folder either.
But when the recipient is a Gmail Business user (email from Gmail engine with custom domain) the emails are received perfectly and into inbox.
So what is the problem? Is it Gmail filtering the mails? Or do I need to add other Headers?
EDIT
Don't know how, but the problem is resolved.
Related
I have following code that uses Swift mailer to send mail via PHP
<?php
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465, 'ssl')
->setUsername('my.email#mydomain.com')
->setPassword('emailpassword');
$message = Swift_Message::newInstance()
->setSubject("This is test subject")
->setFrom(array("sender.email#gmail.com"))
->setTo(array("recipient.email#gmail.com"))
->setBody("This is test mail body","text/html");
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
This works pretty well, the recipient gets an email. But however, if I change username and password in transport to that of gmail like this -
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465, 'ssl')
->setUsername('sender.email#gmail.com') //this is the change, using gmail
->setPassword('senderpassword'); //this is the change
Then this doesnot work.
Can anybody tell me where I m doing wrong? what configuration I m missing?
P.S. I checked SPAM folder as well
Have u check your 2-Step Verification in your gmail account? Is it off? I have same problem before when 2-Step Verification is turned on. I turned it off then it work. Maybe you could give a try.
The only thing that worked is by unlocking the captcha
https://accounts.google.com/UnlockCaptcha‎
I got this answer from This SO Question. See reply with highest upvotes.
i am using php code to send emails to gmail or yahoo ids. i am using a 3rd party mail server to send my emails. my php code works and i can receive the content in my gmail inbox. but where do i save my sent emails ?? who gives me an inbox for all my received / sent emails. suggest me a Name ?
function helloEmail()
{
$from = new Email(null, "test#example.com");
$subject = "Hello World from the SendGrid PHP Library";
$to = new Email(null, "test#example.com");
$content = new Content("text/plain", "some text here");
$mail = new Mail($from, $subject, $to, $content);
$to = new Email(null, "test2#example.com");
$mail->personalization[0]->addTo($to);
//echo json_encode($mail, JSON_PRETTY_PRINT), "\n";
return $mail;
}
There is no inbox for your sent mails. You can send an e-mail using any e-mail address you choose, even if it belongs to someone else or doesn't exist.
For your received e-mail inbox, you'll have to make one yourself via any third party e-mail service such as Gmail or Hotmail, or via your web hosting platform using your own domain name if they provide e-mail services.
To save your sent e-mails you can opt to save them in a database.
How to send email from wamp/xampp localhost?
I have written the following simple code to send message.
I have already edited php.ini,sendmail.ini configuration files but no use,I can't receive email.I want to send message to any gmail address.I can sent email to my domain mail when this piece of code is uploaded via filezilla to my domain, but when I am giving to address as any gmail id, the code is not working.
<?php
$to = "bytecookiestest#gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: swetha851991#gmail.com";
$s=mail($to,$subject,$txt,$headers);
if($s)
echo "success";
else
echo "failure";
?>
It's most likely a problem with the from-header you're sending. You're using your own Gmail-address to send mails from, but that also means you have to use the Google SMTP server. The credentials of swetha851991#gmail.com are the credentials you have to use to authenticate with the SMTP server. It'll otherwise be marked as spam.
Another option is to set the from-address to an address from the domain you're sending it from. If you domain is example.com, you can set the from-address to anything#example.com.
hi I'm working with php imap functionality,
I'm parsing mails from my mail box and storing them into mysql,:
i'm storing following information:
From
To
Subject
Content
Time of receiving mail
After one hour I'm sending back this mail. for sending mail i'm using ses mail of amazon.
I create a mail using the saved data and sending them to my gmail again.
But it is not showing up as group or conversion in gmail.
Here is my code for sending mail:
function sendEmail($pendingMail) {
$sesAccUserName = 'noreply#mydomain.com';
$ses = new AmazonSES(array("key" => AWSAccessKeyId, "secret" => AWSSecretKey));
$source = trim($sesAccUserName);
$destination = array('ToAddresses' => array(trim($pendingMail['email_reminder_send_to_address'])));
$messageBody = $pendingMail['email_reminder_content'];
$messageSubject = $pendingMail['email_reminder_subject'];
$messageArr = array('Subject.Data' => 'Fwd: '.$messageSubject, 'Body.Html.Data' => $messageBody);
$rSendEmail = $ses->send_email($source, $destination, $messageArr);
if ($rSendEmail->status == 200) {
changeStatus($pendingMail['email_reminder_id'], 'completed');
} else {
print_r($rSendEmail);
}
}
Mail sent successfully but it is not grouped with the original message?
I think i googled a lot but not find anything useful..
I'm at beginner level about emails...
will you help me to solve this issue...
Thank you !!!!!!!!!!
I research some gmail inbox mails and found that each mail have a message-id in header,
When we reply to mail the value of message-id is set to a header field In Reply To: of the reply mail (the mail we are sending in reply).
This message-id and In Reply To are responsible for grouping of message in gmail...
Hello and thank you for any help in advance.
I'm using swiftmailer, SMTP transport method to send email from my PHP script.
Sending the message is fine. It works.
The problem is, no matter what I set the FROM,REPLYTO,SENDER settings to, The email comes through as the GMAIL mailbox (ME - me#mydomain.com) instead.
$transport = Swift_SmtpTransport::newInstance('imap.gmail.com', 465,'ssl')
->setUsername($login)
->setPassword($password)
;
$message = Swift_Message::newInstance($subject)
->setFrom(array('test#testdomain.com' => 'test mcttest'))
->setReplyTo(array('test#testdomain.com' => 'test mcttest'))
->setSender('test#testdomain.com')
->setTo(array($to))
->setBody(wordwrap($body, 70))
->setContentType('text/plain')
;
So the email goes through fine, but instead of being from TEST-test#testdomain.com as the sender... it's ME-me#mydomain.com
I switch to a separate (non-gmail) SMTP server to test and the email went through fine, without any problems... definitely think it's a GMAIL thing.
Anyone know how to get around this?
Yes, it is Gmail that changes the sender e-mail address to be the same of the account you are authenticating. There is no workaround for that, except maybe becoming a paid customer of Google Apps.
Funnily enough I've come across the same issue. But as a bit of an insight, I think this is actually a Swiftmailer issue.
There are other libraries and frameworks (Codeignitor pops in my head) that will let you use Googlemails SMTP servers while masking the from address as an email address of your choosing.