The following script sends email using mail function . But i am unable to send an email.Upon clicking submit this gets displayed :
Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in E:\xampp\htdocs\feedback.php on line 19
mail sent successfully
SCRIPT
<?php
if( isset( $_REQUEST['email'] ) ) {
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
mail("me@gmail.com" , $subject , $message , "From:".$email );
echo "mail sent successfully";
} else {
echo "<form method = 'post' action = 'feedback.php'>
Email of sender : <input name = 'email' type = 'text' /> <br/>
Subject : <input name = 'subject' type = 'text'/> <br/>
Enter your feedback here : <textarea name = 'message' rows = 15 cols = 40 > </textarea> <br/>
<input type = 'submit'/>
</form>";
}
?>
I am using Apache as php server
Also tell why we have to write $subject , $message i.e with the $ sign in the mail argument , since we have declared $email , $message etc. , just above. Why can’t we just write message , email , .. without the dollar sign?
You’re using XAMPP which by default comes with Mercury, which is not configured to send mail to a different server by default. It is basically there for debugging. Instructions do exist to configure it to do so, but Windows + Apache is generally best only as a debugging environment in my experience.
PHP variables all have the $ before them. It’s called a
sigil. It is what distinguishes them from, say, constants, class definitions, and functions. If you want to assign a value and then send it into a function, you need to use variables. You can usedefineto set a constant if it is important enough, but trust me, those situations are rare and you should generally avoid them.You can also do this, however: