简体   繁体   中英

PHP - Sending Mail is not working

I've seen some other posts on this, and I'm learning from a book right now. I've followed what the book said and I'm not understanding what I'm missing.

I tried not to make it a double post, but the codes are quite different from the ones I read on stackoverflow so here I go. I hope someone can help me. I am a complete beginner.

My Basic.php has this script

<form action="sendmail.php" method="POST">
<p><strong>Name:</strong><br />
<input type="text" size="25" name="name" /></p>
<p><strong>E-Mail Address:</strong><br />
<input type="text" size="25" name="email" /></p>
<p><strong>Message:</strong><br />
<textarea name="message" cols="30" rows="5"></textarea></p>
<p><input type="submit" value="send" /></p>
</form>

My sendmail.php has this script.

echo "<p>Thank you, <b>" . $_POST['name'] . "</b>, for your message!</p>";
echo "<p>Your e-mail address is: <b>" . $_POST['email'] . "</b>. </p>";
echo "<p>Your message was: <br/>";
echo $_POST['message']."</p>";
//start building the mail string
$msg = "Name: " . $_POST['name'] . "\n";
$msg .= "E-mail: " . $_POST['email'] . "\n";
$msg .= "Message: " . $_POST['message'] . "\n";
//set up the mail
$recipient = "myemail@gmail.com";
$subject = "Form Submission Results";
$mailheaders = "From: me \n";
$mailheaders .= "Reply To " . $_POST['email'];
//send the mail
mail($recipient, $subject, $msg, $mailheaders);

And here is my php.ini that I've changed (this part I have no clue about).

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = myemail@gmail.com

I'd appreciate any help I can get. Thank you!

BTW I'm getting the following error: Warning: mail(): SMTP server response: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 wx2sm302658igb.4 - gsmtp in C:\\wamp\\www\\sam\\sendmail.php on line 24

Your PHP code looks fine but probably you won't be able to send e-mail using PHP's core mail function, via gmail 's SMTP server. Have a look to this post as it could help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM