0

SOLVED

The freaking error was having "inc" in the from address. CHANGED $from = "[email protected]"; to $from = "[email protected]"; and it worked.

I can't get this working. On another site I had, I used a similar method, but with a database and it works. When I use it this way without a database, for some reason it won't work. I can't get a message to send out.

<?php
if (isset($_POST['send'])) {
 $name = $_REQUEST['name']; 
 $email = $_REQUEST['email'];
 $phone = $_REQUEST['phone'];
 $subject = $_REQUEST['subject'];
 $message = $_REQUEST['message'];
 $semail = "[email protected]";

 $name = htmlspecialchars($name, ENT_QUOTES);
 $email = htmlspecialchars($email, ENT_QUOTES);
 $phone = htmlspecialchars($phone, ENT_QUOTES);
 $subject = htmlspecialchars($subject, ENT_QUOTES);
 $message = htmlspecialchars($message, ENT_QUOTES);

 $from = "[email protected]";
 $headers = "From: $from";
 $message .= "Courtesy Care, Inc. Contact\n\n"; 
 $message .= "The following information was collected from Courtesy Care, Inc.'s Contact Form.\n\n";
 $message .= "<table><tr><td>Name:&nbsp;</td><td>".$name."</td></tr><tr><td>Email:&nbsp;</td><td>".$email."</td></tr><tr><td>Phone:&nbsp;</td><td>".$phone."</td></tr><tr><td>Subject:&nbsp;</td><td>".$subject."</td></tr><tr><td>Message:&nbsp;</td><td>".$message."</td></tr></table>"; 

 mail($semail, "Courtesy Care, Inc.", $message, $headers); 

 header ('Location: contactusdone.php?say=msent');
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 <table style="text-align:left; width: 500px; left:45px; position:relative; padding:2px; border:1px solid #1A1A1A">
 <tr>
  <td colspan="2" style="vertical-align:top; text-align:center; border:1px solid #1A1A1A; background-color:#A52A2A; color:#FFFFFF;">MESSAGE FORM</td>
 </tr>
 <tr>
 <td colspan="2"><center>The form below can be used to send a detailed message to <strong>[email protected]</strong>.<br /><br /></center></td>
 </tr>
    <tr>
        <td width="80" align="right" valign="top">Name:&nbsp;</td>
        <td width="302" align="left" valign="top"><input name="name" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td align="right" valign="top">Email:&nbsp;</td>
        <td align="left" valign="top"><input name="email" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td align="right" valign="top">Phone:&nbsp;</td>
        <td align="left" valign="top"><input name="phone" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td align="right" valign="top">Subject:&nbsp;</td>
        <td align="left" valign="top"><input name="subject" type="text" style="width:98%" /></td>
    </tr>
    <tr>
        <td align="right" valign="top">Message:&nbsp;</td>
        <td align="left" valign="top"><textarea name="message" style="width:98%; height:150px;"></textarea></td>
    </tr>
    <tr>
  <td colspan="2" align="right"><input type="reset" value="Clear Fields"> <input type="submit" name="send" value="Send" /></td>
    </tr>
    </table>
</form>
1
  • You should post your solution as an answer and then accept it, rather than editing it into your question. Commented Jan 22, 2011 at 6:56

1 Answer 1

1

Are you sure the message is actually sending? Or, if it's sent, it's not getting dumped as spam?

PHP's mail() function essentially lies to you. If it returns true, that doesn't mean the mail got to the person it's addressed to, it just means that's it's been accepted into the mail system. Think of it as the difference between dropping a letter into a mailbox and the letter actually getting delivered - there's still plenty of ways for the postal system to shred the thing before it goes anywhere. All mail() will guarantee is that you dropped it into the mailbox.

Sign up to request clarification or add additional context in comments.

4 Comments

I know when it's sent because I send it directly to me. This is the first time I'm having trouble with this.
I can't see what a database has to do with sending mail, other than producing data which goes into a mail message. Check the server's mail log to see what's happening to the message after PHP's handed it over to the local MTA (sendmail, postfix, exim, etc...). And check the return value from mail. If it's false, there was a problem sending it at the PHP level.
I think one of the problems was having "$message = $_REQUEST['message'];" which is the same variable and conflicts with "$message .=", I can't seem to see the other problem.
SOLVED The freaking error was having "inc" in the from address.$from = "[email protected]";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.