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/
Related
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!');
}
?>
Hi I have used sendgrid to send emails in the past and am using it as a reset password on an app currently. I want to use it for another app also. My AWS has a new instance for the second app. I have copied the sendmail.ini from my first instance and the php.ini and I am using basically the same code for sending emails in my php files. The first is working, the second isn't. Code below:
$subject = "Don't be stuck for a password!" ;
$Emessage = wordwrap("<html><body>Please click the link below to reset your password. <br><br> <a href=http://xxx.xxx.xx/resetPassword.php?AuthCode=".$Token."&email=".$email."&userid=".$userid." />Reset Password</a><br><br> Thanks, <br></body></html>", 70, "\r\n");
$from= "xxx#xxx.com";
$from_name="xxx Ltd.";
$headers = "Date: ". date("r") ."\r\n". "From: $from_name <$from>\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//echo $message;
$mailSent= mail($email, $subject, $Emessage, $headers);
if (!$mailSent){
//$reset= error_get_last();
$reset='Not OK';
}
Note the mailSent is returning true. It must be some config issue. Also, I am running the same version of xampp on both instances.
My sendmail.ini is as follow:
[sendmail]
smtp_server=smtp.sendgrid.net
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=xxx
auth_password=yyy
force_sender=xxx#xxx.com
and my php.ini has the following in the [mail function]:
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" - t"
Since the same code is working on one instance and not the other, if we assume the instances are exactly the same, it must be external to your instance. AWS has an initial outbound email limit, so it's possible you're hitting that, but it's been lifted on your other instance.
One way to get around this, is to send via SendGrid's Web API (which is not limited on AWS [as it sends over port 80]).
You won't be able to send using the mail function, however, we have a PHP Library to send email that makes it easy enough to do.
Turns out I made the rookie mistake of not restarting my Apache! That was all that was wrong!
I have a register script that sends an email to who ever signs up.
//// Set headers ////
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= "Content-type: textrn";
$headers .= "From: $from";
/// Send the email now ////
mail($email1, $subject, $message, $headers, '-f nleachman#stayontrack.net');
//mail($email1, $subject, $message, $headers, '-f noreply#your-email.com');
$db->commit();
echo "Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!";
$db = null;
exit();
}
catch(PDOException $e){
$db->rollBack();
echo $e->getMessage();
$db = null;
exit();
}
Here is my SMTP server used for configuration:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = nleachman#stayontrack.net
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
When ever I try to run my log-in script I get this:
Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!
My problem is that who ever signs - up never recieves the email. At first I thought that it may just be an impossible function on localhost. Then however, I saw some codes that worked for other people but gave me an error like...
Variable $From not set
How could I configure my code so that it runs without errors?
Also, how could I configure the code to make sure who ever the email is sent to recieves it?
For using SMTP within PHP, you should have a look at phpmailer. https://github.com/Synchro/PHPMailer
easy to configure and does all the work for you.
You're using mail() to send the email - I've had problems with this before not sending to certain domains like hotmail. I'd give PEAR mail a go - http://pear.php.net/package/Mail/redirected.
I've written a mail script as;
<?php
$to = 'something#domain.com';
$subject = 'This is subject!';
$body = 'Welcome to our website!';
$headers = 'From: myemail#mydomain.com' . "\r\n" .
'Reply-To: myemail#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent = mail($to, $subject, $body, $headers);
if($sent) {
echo "Your mail has been sent to ". $to .".";
} else {
echo "You mail was not sent.";
}
?>
And I could see the echo "Your mail has been sent to someone#somedomain.com" for mail being sent in all of the cases regardless of what email is but the emails are being delivered only to something#gmail.com but never on something#hotmail.com or something#yahoo.com or something#domain.com (hosted on google apps).
I wonder if there is any server configuration missing or the server has been blocked for hotmail/yahoomail or any error there is? Is there any thing you guys can help/suggest me for this?
I've configured my cPanel mail to be recieved at google apps, but I think that doesn't matter as I am trying to send mail, not recieve with this code here.
And yes, I've tried checking in the SPAM/JUNK folders and also waited lots of minutes to see them not being delivered. ;(
Hello Please check sender email sendbox also ,there may be mail in sendbox with some error message. or it may be that on your host the reverse DNS wasn't setup correctly..thanks.
You must authenticate your email with your password before sending, so it won't get blocked in the server. if you use mail class like phpmailer to send mails, following example will help you.
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
Php mailer -- Download phpmailer in this website.
SMTP demo -- Nice tutorial how to use php mailer to send authenticated mails.
All,
I have the following code:
$to = $friend_email[$x];
$subject = "Subject";
$message = "This is a message";
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
When the email sends (I'm using Godaddy's hosting service) it says From correctly but then in gmail it says via pxnlhgxxx.prod.xhx3.secureserver.net. Is there anyway to hide the via part or make it say something like website.com? Thanks for the help.
As per the mail() docs, you use the optional 5th parameter for the function and pass in the name of the server you'd like to masquerade as:
mail($to, $subject, $message, $headers, "-f sender#website.com");
If your hosting off godaddy then something like that will happen. You can use your own SMTP server, or use Google free SMTP Server (logging in with your gmail account). Host Gator does the same thing.
You can prevent Google from showing the 'via' notice by DKIM signing your outgoing mail to prove that you genuinely control the domain you're sending e-mail on behalf of.
Its all up to the configuration of the smtp server.