Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.