Page 1 of 2

Newsletter Submit Code

Posted: Fri Feb 17, 2006 6:34 pm
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

Posted: Fri Feb 17, 2006 7:52 pm
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);

Posted: Fri Feb 17, 2006 8:02 pm
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.

Posted: Fri Feb 17, 2006 8:05 pm
by Benjamin
Sendmail.php and then put your header redirect below it.

Posted: Fri Feb 17, 2006 8:06 pm
by melrox
sorry, what's the header redirect?

is it ?>

Posted: Fri Feb 17, 2006 8:07 pm
by Benjamin
It's your:

Code: Select all

header( "Location: http://www.ironworksmusic.com/thankyou.html" );

Posted: Fri Feb 17, 2006 8:07 pm
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

Posted: Fri Feb 17, 2006 8:10 pm
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.

Posted: Fri Feb 17, 2006 8:15 pm
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?

Posted: Fri Feb 17, 2006 8:17 pm
by Benjamin
I meant post what is in it now so I can fix the error.

Posted: Fri Feb 17, 2006 8:18 pm
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" ); 
?>

Posted: Fri Feb 17, 2006 8:18 pm
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.....

?>

Posted: Fri Feb 17, 2006 8:21 pm
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.

Posted: Fri Feb 17, 2006 8:27 pm
by melrox
i'm still getting this error...could it be the newsletter.html code i posted in the beginning?

Posted: Fri Feb 17, 2006 8:31 pm
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.