Newsletter Submit Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Newsletter Submit Code

Post by melrox »

Hey, this is my first php coding attempt. I'm half way there. I'm setting up a Newsletter submit form on this site: http://www.ironworksmusic.com go to home page and click on newsletter. There are several fields that my client wants to obtain. Through tutuorials from several places, I've figured out how to at least get the email addresses registered and sent to myself, but I don't know how to tell the code to email me the name, age, etc of the other fields. Most tutorials and such are much more involved than i feel is required. If anyone could tell me directly what is lacking it would be a huge relief.

Here is the code that is my Newsletter.html:

</script>
<FORM METHOD=POST ACTION="sendmail.php">
<INPUT TYPE=HIDDEN NAME="to" VALUE="upscene@mac.com">
<INPUT TYPE=HIDDEN NAME="subject" VALUE="Ironworks Newsletter Signup">
<INPUT TYPE=HIDDEN NAME="submit" VALUE="http://www.ironworksmusic.com/thankyou.html">

Here is the code that is in my Sendmail.php:

<?
$email = $_REQUEST['email'] ;

mail( "upscene@mac.com", "Ironworks Newsletter Signup", "From: $email", "email: $email" );
header( "Location: http://www.ironworksmusic.com/thankyou.html" );
?>

thanks!
mel
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

// this should do the trick, but there are no security checks.


$name = $_POST['name'];
$email = $_POST['email'];
$state = $_POST['state'];
$age = $_POST['age'];
$comments = $_POST['comments'];

function send_mail($from, $to, $subject, $body) {
  $header = "From: " . $from . "\n";
  $mail_to = $to;
  mail($mail_to, $subject, $body, $header);
}

$message = $name . " wants to be added to the email newsletter. " . $name . " is in " . $state . " and is " . $age . " years old.\n\n";
$message .= $name . " said, " . '"' . $comments . '"';
send_mail("From Name <blah@blah.com>", "To Name <blah@blah.com>\n", "Subject", $message);
melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Post by melrox »

should all of that go in the Sendmail.php or does any part of that go in the Newsletter.html?

thanks so much! I really appreciate it.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Sendmail.php and then put your header redirect below it.
melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Post by melrox »

sorry, what's the header redirect?

is it ?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

It's your:

Code: Select all

header( "Location: http://www.ironworksmusic.com/thankyou.html" );
melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Post by melrox »

i've put all that in the Sendmail.php and when Submit is hit, it's overriding the behavior i have on it to open my thankyou.html and it's showing this error:


Parse error: syntax error, unexpected T_VARIABLE in D:\websites\a-com\ironworks\www\sendmail.php on line 2
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Post the code of sendmail.php and make sure you use the php button in this forum so that it displays as code.
melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Post by melrox »

crap, i'm sorry.

i'm not sure how to be sure of that. I just copied all of your code and pasted it into my sendmail.php and erased what i had before?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I meant post what is in it now so I can fix the error.
melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Post by melrox »

<?
$name = $_POST['name'];
$email = $_POST['email'];
$state = $_POST['state'];
$age = $_POST['age'];
$comments = $_POST['comments'];

function send_mail($from, $to, $subject, $body) {
  $header = "From: " . $from . "\n";
  $mail_to = $to;
  mail($mail_to, $subject, $body, $header);
}

$message = $name . " wants to be added to the email newsletter. " . $name . " is in " . $state . " and is " . $age . " years old.\n\n";
$message .= $name . " said, " . '"' . $comments . '"';
send_mail("From Name <upscene@mac.com>", "To Name <upscene@mac.com>\n", "Subject", $message); 
header( "Location: http://www.ironworksmusic.com/thankyou.html" ); 
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You do realize that you have to put tags before and after the code....

ie

Code: Select all

<?php

// all the code goes here.....

?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

There is no error in that code. I tested it on my system and it redirected to your thank you page. I would change the <? to <?php


Please use the PHP tags when posting in this forum. These are located above where you type your message.
melrox
Forum Newbie
Posts: 8
Joined: Fri Feb 17, 2006 6:28 pm

Post by melrox »

i'm still getting this error...could it be the newsletter.html code i posted in the beginning?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

No, the code you posted above that I wrote works fine, and there isn't a parse error on line 2. Either you only posted part of the file or didn't upload it to your server or you changed a different file.
Post Reply