heathergem Posted October 19, 2007 Share Posted October 19, 2007 I have created my first PHP script, and I'm very proud of myself ... only it's not working. I had it working at one point; but then I tried to add another element (BCC), failed, and then couldn't find my way back. This script is to send the information from an html form to my email ( to forward an article from my web site). Here's the form: <table> <form name="sendarticle" method="POST" action="sendarticle1.php"> <tr> <td colspan=2 class="emailfont"><div style="padding:0 0 7px 0;">Email this article to a friend. Just fill out the form and send.</div></td> </tr> <tr> <td class="emailfont" align=right><b>FROM NAME</b></td> <td><input type="text" name="name" size="35"></td> </tr> <tr> <td class="emailfont" align=right><b>FROM EMAIL</b></td> <td><input type="text" name="email" size="35"></td> </tr> <tr> <td class="emailfont" align=right><b>TO EMAIL</b></td> <td><input type="text" name="to" size="35"></td> </tr> <tr> <td class="emailfont" align=right><b>MESSAGE</b></td> <td><input type="textarea" name="message" size="35"></td> </tr> <tr> <td colspan=2 align=right><INPUT type="submit" value="send"></td> </tr> <tr> <td colspan=2 class="emailfont"><br></td> </tr> <tr> <td colspan=2 class="emailfont"><b>Title of article:</b></td> </tr> <tr> <td colspan=2 class="emailfont">blah blah blah<br></td> </tr> <input type="hidden" name="subject" value="blah blah blah" /><br/> </tr> </form> </table> Here's the PHP script: <?php $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $to = $_REQUEST['to'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; mail( $to, $subject, '$message\nhttp://www.example.com/#example', 'From: $name <$email>' ); header( "Location: http://example.com/thankyou.html" ); ?> When the form is filled out, it properly redirects, but the email does not arrive. What am I doing wrong? Also, how do I add BCC to this so I can get a copy of the message sent. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/73935-solved-mail-form-troubleshoot/ Share on other sites More sharing options...
Wes1890 Posted October 19, 2007 Share Posted October 19, 2007 You can't include $vars inside of 'single quotes' So what I do is use "double quotes" and put my vars {inside brackets} <?php $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $to = $_REQUEST['to'] ; $message = $_REQUEST['message'] ; $subject = $_REQUEST['subject'] ; // I changed this line $mail_it = mail( $to, $subject, "{$message}\nhttp://www.example.com/#example", "From: {$name} <{$email}>"); // See if the mail has been sent.. just something I like to do if (!$mail_it) { die("Mail NOT Sent"); } else { header( "Location: http://example.com/thankyou.html" ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73935-solved-mail-form-troubleshoot/#findComment-373145 Share on other sites More sharing options...
heathergem Posted October 19, 2007 Author Share Posted October 19, 2007 Thank you for helping me! It didn't work though. I copied the code, and tried out the form. Same as before. It redirects to the right site and acts as though the message has been sent, but it hasn't. I check my junk box and tried a friend's address. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/73935-solved-mail-form-troubleshoot/#findComment-373170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.