Page 1 of 1

Mailing list - I'm a musician not a web developer!

Posted: Sat May 06, 2006 7:39 am
by Mr Winstanley
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, trying to get this mailing list working for our band website. As I'm a poor musician, I've learned to do this myself but can't quite get it working.

As a user, when you submit your details it says 'thanks, you've been added to the list etc..', but I don't actually recieve an email telling me their details so I can add them to my list. I'm not using a database or anything just making my own list of the names.

When I first put it up it worked fine, but all of a sudden it just stopped, and I hadn't changed anything.

HELP PLEASE!

[b]THIS IS MY PHP[/b]

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<html> 
<head> 
<title>Official Homepage</title> 
</head> 
<body> 
<?php

$potential_member_name = $_POST['name']; 
$potential_member_email = $_POST['email'];

$email_subject = 'New mailing list subscriber';

$email_body = 'this fellow or perhaps fine young lady wants to hear more from us'; 
$email_body .= "name is $potential_member_name"; 
$email_body .= "email is $potential_member_email";

$from_name = 'Winters Web Lord'; 
$from_email = 'webmaster@example.com';

$headers = "from: $from_name <$from_email>\r\n"; 
$headers .= "reply-to: $from_name <$from_email>\r\n"; 
$headers .= "return-path: $from_name <$from_email>\r\n"; 
$headers .= "content-type: text/plain; charset=iso-8859-1\r\n"; 
$headers .= "x-priority: 1\r\n"; 
$headers .= "x-msmail-priority: normal\r\n"; 
$headers .= "x-mailer: php\r\n";

$to_email = 'mail@example.com';

mail($to_email, $email_subject, $email_body, $headers);

echo "<p>Thankyou $potential_member_name, your email address 
($potential_member_email) has been added to our list. You shall hear from us 
soon!</p>";

?>

</body> 
</html>
AND THIS IS THE LITTLE FORM IT SITS IN

Code: Select all

<div id="form"> 
<img src="joinmail.jpg" alt="Join the mailing list!"/> 
<form action="thanks.php" method="post" > 
<p>Name : <input type="text" name="name" size='30' value='' maxlength='60'/></p> 
<p>Email : <input type="text" name="email" size='30' value='' maxlength='60'/></p> 
<p><input type="submit" value="submit" name="submit"/></p> 
</form> 
</div>
THANKS EVERYONE!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: Mailing list - I'm a musician not a web developer!

Posted: Sat May 06, 2006 7:57 am
by timvw
Mr Winstanley wrote: When I first put it up it worked fine, but all of a sudden it just stopped, and I hadn't changed anything.
Instead of confronting us with things that haven't changed (your code) you should better try to identify what has changed...

Has the webserver/php configuration been changed?
Are there new error/warning messages in the errorlog?
Does your mailserver still accept e-mails coming from your webserver?
Do you have an e-mail client that filters data?
...


Btw, it appears that your current code is wide open for attacks since you don't validate the incoming data. Do you really want to accept email addresses with \r and \n in them?
Do you know how \n can affect the workings of the mail function?
...

Posted: Sat May 06, 2006 7:58 am
by feyd
Have you checked your server's error logs? mail() may be having some issues with sending the email. You may want to try phpmailer or our own d11wtq's emailing class.

Posted: Sun May 07, 2006 5:46 am
by aerodromoi
I'd suggest placing the name and the email address of the prospective member into the email body rather than its header if you don't want to validate them (eg. using regular expressions). Using unvalidated user input in the header part is far too risky (btw: your web host won't appreciate getting blacklisted).

You might also want to check whether the user has actually submitted something...

Code: Select all

if (empty($potential_member_name) OR empty($potential_member_email)) {
  die ("No name / No email address given!");
}
aerodromoi