Sending e-mail from a local host - php

I am trying to send an email from localhost, and the program I am using is MAMP. I have looked this up online and done everything written, but this still won't work. The function I have entered in my PHP file to send emails is:
mail(
$admin_email, $messaage,
'Works!',
'An email has been generated from your localhost, congratulations!');
furthermore, I have filled out all the send mail value as shown below:
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=25
smtp_ssl=ssl
auth_username=****#gmail.com
auth_password=*******
hostname=localhost
Obviously - my email and password are filled out using my email and password. Also I have altered the php.ini file as shown:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;http://php.net/sendmail-path
sendmail_path = C:\Windows\System32\sendmail\ -t -i -f my_email#gmail.com
Can someone tell me where my error is?

You're not going to be able to send via Google's SMTP server because the mail() function doesn't perform SSL or TLS authentication, which is required. See this answer for more information. You should consider using the PHPMailer class instead.
Also, please note that you're using mail() incorrectly. You have
mail(
$admin_email, $messaage,
'Works!',
'An email has been generated from your localhost, congratulations!');
The second argument should be a subject, and the third should be the message. The fourth argument is optional and is supposed to contain extra mail headers:
additional_headers (optional)
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
It is not for a plaintext message like you are using. By adding plaintext where a properly-formatted header should be, you are likely to break some servers and some mail readers.

If you are using smtp_port=25you have to change smtp_ssl=none or use this
smtp_port=587
smtp_ssl=tls
Have you changed these settings from your gmail account
Access your email account. Click the Gear Tool > Settings > Forwarding
and POP/IMAP > IMAP access. Click "Enable IMAP", then save your
changes
For check email use these code
<?php
$to = 'myemail#yahoo.com';
$subject = 'Fake sendmail test';
$message = 'If we can read this, it means that our fake Sendmail setup works!';
$headers = 'From: myemail#egmail.com' . "\r\n" .
'Reply-To: myemail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
echo 'Email sent successfully!';
} else {
die('Failure: Email was not sent!');
}
?>

Related

msmtp 1.8.22 override from address when sending via php

I have the following config file for msmtp
account default
host SES_HOST
port 587
timeout 5
auth on
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
syslog on
set_from_header on
allow_from_override off
user SES_USERNAME
password SES_PASSWORD
from SES_VERIFIED_EMAIL
php.ini
sendmail_path = /usr/local/bin/msmtp -ti
I want to make sure all emails sent via php use the SES_VERIFIED_EMAIL in the from header so SES does NOT reject the email. I thought setting the from allow_from_override on and allow_from_override off would mean that email send from php with a from header that is NOT SES_VERIFIED_EMAIL would be replaced by SES_VERIFIED_EMAIL so the message will be sent
But I can only send emails via php where the from header is already put in as SES_VERIFIED_EMAIL but I need it to work in all cases. It doesn't appear the from header is being replaced
I want msmtp to override the From header to SES_VERIFIED_EMAIL so it does get sent. I thought the settings above would do it.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: NOTSESVERIFYED#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Change:
set_from_header on
To:
set_from_header off
Try:
from SES_VERIFIED_EMAIL
rewrite_domain SES_VERIFIED_EMAIL
The rewrite_domain option is used to rewrite the domain part of the From header. This is useful if you want to send mail from a domain that is not your own. The domain part of the From header is rewritten to the value of the rewrite_domain option. The local part of the From header is not changed.

Add Header Flag in YiiMailer

Problem
While Sending Mail via Postfix and through Amazon SES it throws me a ,
554 Message rejected: Email address is not verified.
Error message, And i have verified my From Email address and Amazon SES is in the production environment , so no issue there. This is what Amazon documentation says :
Email address is not verified—Your account is in the sandbox and one
of the recipient email addresses has not been verified. This might
apply to "Sender", "Return-Path", or "From" addresses.
If you have not requested production access to Amazon SES, you must
verify every recipient email address except for the recipients
provided by the Amazon SES mailbox simulator. You must also verify
your own "From" address. For more information, see Verifying Email
Addresses and Domains in Amazon SES and Testing Amazon SES Email
Sending.
SO, After searching for solution i found out a BLOG POST explaining the fix for this issue, which says adding -f flag in email will solve this issue,
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: michael#chtoen.com' . "\r\n" .
'Return-Path: michael#chtoen.com' . "\r\n" .
'Reply-To: michael#chtoen.com' . "\r\n";
mail($to, $subject, $message, $headers, '-f michael#chtoen.com');
?>
Which actually does solve the issue, But I cannot set it to the YiiMailer. For now i am adding this flag directly to php.ini as ,
sendmail_path to usr/sbin/sendmail -t -i -f "noreply#sbworkbench.com"
It works fine. But I don't want to do it this way.
What I have done
Is , Create the YiiMailer setup as ,
$mail = new YiiMailer('customerEmail', $data);
Common::setup_smtp($mail);
$mail->setLayout('mail');
$mail->render();
$mail->From = Yii::app()->params['adminEmail'];
$mail->FromName = 'PENDING NOTIFICATION';
$mail->Subject = $data['subject'];
$mail->AddAddress($data['sendTo']);
And for adding the flag I have tried ,
Adding the flag itself in the From address : Results the same
invalid email
$mail->From= "-f exaple#example.com"
Adding extra parameters "Form" with value as "-f exaple#example.com" : Results Duplicate Form Address (which is obvious :D)
Question :
How can I set header flag using YiiMailer ?
Is it related to misconfiguration of Postfix with Amazon SES ? However, The same setting is working fine for Java Application.
P.S
The code works on sendmail and swiftmail without Amazon SES with no
need of the header flag.
YiiMailer is a wrapper for PHPMailer. You can set the -f flag by setting the $Sender property of PHPMailer.
$mail->Sender = "michael#chtoen.com"

Never receive email from form- gmail

This is the mail that should send (code in my PHP):
$message =
"Hello \n
Thank you for registering with us. Here are your login details...\n
User ID: $user_name
Email: $usr_email \n
Passwd: $data[pwd] \n
";
mail($usr_email, "Login Details", $message,
"From: \"Member Registration\" <xxxx#gmail.com>\r\n" .
"X-Mailer: PHP/" . phpversion());
header("Location: thankyou.php");
exit();
and my sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=xxxx#gmail.com
auth_password=xxxxxxx
force_sender=xxxx#gmail.com
I'm a complete beginner so this could be totally wrong.
When I submit the form where the mail function is, the thankyou.php page appears as specified
Try phpMailer. You're not forming the mail properly to be acceptable by google... use this class to send a standard mail.
It won't work because GMail is using different SMTP ports with SSL, and you are using the port 25.
You should try some website found on Google to find out how to set your SMTP server properly with sendmail, like this one : http://appgirl.net/blog/configuring-sendmail-to-relay-through-gmail-smtp/

PHPs mail function doesn't send email to some servers

I have the following code which works on some servers and does not work on others:
$Name = "myname"; //senders name
$email_sender = "myemail.dia#gmail.com"; //senders e-mail adress
$recipient = $email; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email_sender . ">\r\n";
$status = mail($recipient, $subject, $mail_body, $header);
print('ENVOI '. $status);
The $status variable is true but I don't see any email.
$status being true doesn't mean the mail was RECEIVED by your recipient. It just means the mail function successfully delivered the mail to the LOCAL delivery agent. After that it's out of PHP's hands.
The process looks something like this:
PHP script calls mail()
mail() delivers message to the local mail server (sendmail, postfix, exim, etc..)
mail(), having successfully completed 'delivery' of the email, returns TRUE
local mail server connect's to recipient's mail server, delivers mail
recipient's mail server does whatever it has to to get the email into the recipient's inbox.
Since mail() is returning true, that means that at least your sending code is correct enough to not cause things to blow up at that stage. That leaves delivery problems between your and the recipients' mail servers:
a) Perhaps the recipient is using greylisting (in which case the mail SHOULD eventually show up). Maybe your server gives up before the greylist timeout period expires, so the retry attempt(s) is never made.
b) your mail server is blacklisted. Your server, and/or some other potential spam source is in the same netblock have been added to one or more anti-spam RBL lists the recipient subscribes to.
c) Perhaps the remote server is very prickly about header correctness and your server's a bit too relaxed about one or more headers.
At least these problems SHOULD be visible in your own mail server's maillog (generally /var/log/maillog on most Unix-ish systems). Try sending a test mail while watching the log to see how the message procedes through the system. Also check the server's outgoing mail queue (mailq command, usually). Maybe the missing messages are stuck in there.
And then there's the bigger problems:
d) the remote mail server is accepting the message, but silently tossing it because it's flagged as spam or as infected. This you can't detect from your own mail logs, as this is done purely on the recipient end. All you'll see is the "250 OK" success message.
For this you'll need the recipient's help in diagnosing the problem.
This may or may not be related but you have a pretty simple header, I would replace your header variable with something like what's below and see if that changes anything for you.
$headers = 'From: ' .$email_sender. "\r\n" .
'Reply-To: ' .$email_sender. "\r\n" .
'X-Mailer: PHP/' . phpversion();
Make sure you smtp setting are correct on the servers in question.

PHP mail not showing up at Gmail but shows up at Hotmail and other 3rd party/ISP account

I have 2 sites where mail is sent to two vanity gmail accounts. I'm using PHP to handle the mail, but the mail is not showing up at gmail (not in spam/junk, it just doesn't show up). If I switch the PHP to send to my personal hotmail account, the mail shows up. Same for a personal email account through my ISP.
The mail used to show up at those 2 vanity gmail accounts, any ideas why they would just stop?
There is a possibility you did not set proper header data, and those emails are blocked even before reaching spam folder.
Try adding something like this:
$headers = 'From: your#email.com' . "\r\n" .
'Reply-To: some#email.com';
This is the fourth parameter of mail() function.
I have encountered problems in the past where certain free email providers would not receive any email from my servers.
I found that a few things can be the culprit, on top of putting the correct headers in the actual message:
Make sure your server is configured for reverse dns lookup
Make sure you are not running an open smtp relay
Make sure your server did not wind up in any email blacklists (if you had an open relay, you probably got blacklisted.
Chances are, PHP is sending the email just fine, but the Google servers are rejecting any messages coming from your server.
You can test this by doing a quick:
mail -s Test you#gmail.com < /dev/null
If your server is okay, you will receive a message in your gmail, if you don't, PHP isn't the problem.
I've found having a proper SPF record for your domain really helps
http://www.openspf.org/SPF_Record_Syntax
Seems more likely that this is a server configuration issue and not a PHP issue.
As a side note I've found gmail more tolerant than our local system, so I've been able to get messages out to my gmail account, but not my account on the hosting domain.
I don't think Google uses third-party black lists, but they do care about server configuration (does it identify itself correctly, have matching SPF and RDNS records, respond to commands properly). You might try a couple of testing services like this or this.
I see it is too late but ... following code is working for gmail.
<html>
Mail Responder:<br><br>
<?php
$to = $_REQUEST['MyEmail'] ;
$subject = $_REQUEST['subject'] ;
$greeting = $_REQUEST['greeting'] ;
$realname = $_REQUEST['realname'] ;
$HisEmail = $_REQUEST['HisEmail'] ;
$message = $_REQUEST['message'] ;
$headers = 'From: '.$HisEmail;
//$headers = 'From: $HisEmail' . "\r\n" .
//'Reply-To: some#email.com';
$send = mail($to, $subject, $greeting."\n"."\n".$realname."\n"."\n".$HisEmail."\n"."\n".$message, $headers );
if ($send)
$mailReturns = "Mail sent successfully.";
else
$mailReturns = "Mail sent failed.";
?>
<?php echo $mailReturns; ?>
</html>

Categories