chris
chris

Reputation: 137

Sending e-mail from a local host

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   [email protected]

Can someone tell me where my error is?

Upvotes: 2

Views: 848

Answers (2)

Khaled Rahman
Khaled Rahman

Reputation: 141

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      = '[email protected]';
$subject = 'Fake sendmail test';
$message = 'If we can read this, it means that our fake Sendmail setup works!';
$headers = 'From: [email protected]' . "\r\n" .
           'Reply-To: [email protected]' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)) {
    echo 'Email sent successfully!';
} else {
    die('Failure: Email was not sent!');
}
?>

Upvotes: 0

elixenide
elixenide

Reputation: 44841

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.

Upvotes: 2

Related Questions