I cant get mail() to work

A

Anonymous

Guest
I have a simple file, Im trying to learn the basics. I have uploaded these files to a webhost already that has php support

I have an html file that calls a php file that is supposed to do the mail

<form id="feedback" action="feedback.php" onsubmit="alert('Thank you for your feedback')" method="post">
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname"><br><br>
What can we do better to serve you?<br>
<textarea name="feedback" rows="10" col="20"></textarea><br><br>
<input type="submit" value="Submit" onclick="feedbackThanks()">
</form>

and the feedback.php is

<?php

$msg = "Name: ".$_POST["firstname"]." ".$_POST["lastname"]."<br>"."Feedback: ".$_POST["feedback"];

$msg = wordwrap($msg,70);

mail("me@gmail.com","Comment from website",$msg);
?>

For some reason i cant get it to work and email me. Help!!!!
 
For some reason i cant get it to work and email me. Help!!!!

Would you care to expand on the not working part?

What is and isn't doing what you thought?

Are you trying to send the mail from a server or your own pc?
 
Your php script looks good. I copied it to my hosting account and it is running at https://legacy-systems.biz/demos/sendmail/feedback.php
The only change I made was to send the mail to my email address instead of me@gmail.com.

This means the problem is the php where your script is running is not configured to send mail. I have a php script that tests whether php is configured for mail. That script is at the end of this post. You can see it running at https://legacy-systems.biz/demos/sendmail/test.php

It would really help to make sure we are on the same page if you could copy that script into a file where your feedback form is running and then run the test, and post the results here. If it fails, the next step would be to look in your php error log to see what explanation it gives you. Getting your mail to work is going to be a task of setting your php to run mail. I will help you with that, but first, I'd hate to starting working on that without verifying that is the problem.

I really hope you will post the test results here so we can start on the next step.

SCRIPT TO TEST WHETHER PHP IS CONFIGURED FOR EMAIL
Code:
<?php
if (isset($_POST['form-submitted'])):
	$to='postmaster@legacy-systems.biz';
	$subject='mail demo';
	$body='I wish this would just work';
	
	
	
	if(mail($to,$subject,$body)):
		echo('sent. This does not mean the mail will reach the $to address, but this proves this php installation is configured to at least some extent for email.<br>');
	else:
		echo('NOT sent. The problem is this php installation is not configured for email<br>');
	endif;
	die ('<a href="feedback.php">Start over</a>');
endif;

?>
<form id="feedback" action="test.php"  method="post">
<input type="hidden" name="form-submitted" value="yes">
<input type="submit" value="Test if this php can send mail (click)" >
</form>
 
Back
Top