basic php email code - need help

Im new at this, so sorry if the problem is extremely simple.

I am hosting my website ( through and I am trying to use php to make a simple feedback form. As a test, I used the following code (saved to in a file test.php) to see If I could send email from their server:

<?php $to="[email protected]"; $subject="test"; $body="Just testing the email script."; $headers="From:, I got the second message, so obviously something is wrong. I tried searching for answers and many tutorials and sites mentioned that i might have to use ini_set() to set the SMTP and the sendmail_from configurations. I tried calling tech support to ask for the smtp server, and they told me that I didnt have to do anything, just write correct code and upload it to my main directory, which I did. I also asked for help with my email script, but they said they couldnt answer those type of questions.

My questions: So am I missing something in the code? Do the parameters to the mail() function matter, or are they just text for the email message. Also maybe Im asking the wrong questions to tech support, so they’re giving me answers to the wrong problem.
Any help would be greatly appreciated.


I would do a couple of things… echo out everyone one of your variables to make sure they are exactly as you expected. Next I would try using rn at the end of the $header string rather then just n. maybe even break it up into baby steps so we can isolate the problem.
$to="[email protected]";
$body=“Just testing the email script.”;
$headers=“From: [email protected]rn”;
// debugging here
// echo out values
echo $ton$subjectn$bodyn$headers;
// send mail
$sent = mail($to,$subject,$body,$headers)

if($sent) {
echo “An e-mail was sent to $to with the subject: $subject.”;
else {
echo “There was a problem sending the mail.”;

Just a few suggestions. No guarentees.

Thanks for the suggestion.

Ill try it out.

Sponsor our Newsletter | Privacy Policy | Terms of Service