Jump to content

[SOLVED] mail form troubleshoot


heathergem

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/73935-solved-mail-form-troubleshoot/
Share on other sites

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" );
}
?>

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.