Forum Moderators: coopster

Message Too Old, No Replies

Recommend A Friend

More PHP Mailscript Woes

         

sitemaker

12:00 am on Jul 30, 2005 (gmt 0)

10+ Year Member



<?php

if($_POST['referrer']!= '')
{$referrer = $_POST['referrer'];}
if($_POST['fname']!= '')
{$fname = $_POST['fname'];}
if($_POST['femail']!= '')
{$femail = $_POST['femail'];}

$to = ''.$femail.'';
$subject = ''.$fname.', '.$referrer.' Has A Recommendation For You...';
$message = 'RECOMMENDATION';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$fname.' <'.$femail.'>' . "\r\n";
$headers .= 'From: '.$referrer.'' . "\r\n";
$headers .= 'Reply-To: No Reply' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . " \r\n";
mail($to, $subject, $message, $headers);
header("Location: http://www.example.co.uk/thanks.php");
exit();

?>

Hello all,

The intention of this very stripped down mailer is that somebody enters their name (name=referrer), friends name and friends e-mail address (names=fname and femail respectively) in a form, and this script sends an e-mail to the 'femail' value recommending my site. Except, it doesn't.

Mans, this is like learning HTML all over again ;-) What's wrong this time?

[edited by: ergophobe at 4:17 pm (utc) on July 30, 2005]
[edit reason] please don't use three X for sample URL - might give SEs the wrong idea about us! [/edit]

dreamcatcher

6:59 am on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the problem exactly?

The first two lines look like they`ll give a parse error.

Try:

$to = $femail;
$subject = $fname.', '.$referrer.' Has A Recommendation For You...';

dc

sitemaker

11:12 am on Jul 30, 2005 (gmt 0)

10+ Year Member



Thankyou, that fixed it. I always though that each value in the mail parameters ($to, $subject etc...) had to be enclosed by single quotes, and each iteration of a posted value by '.$value.'

Apparently this isn't the case at all.

mcibor

11:59 am on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This would be even clearer:

$to = $femail;
$subject = "$fname, $referrer Has A Recommendation For You...";
$message = "RECOMMENDATION";
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "To: $fname <$femail> \r\n";
$headers .= "From: $referrer \r\n";
$headers .= "Reply-To: No Reply \r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . " \r\n";

Variables in " " are being parsed, in ' ' are not.
Best regards
Michal Cibor

dreamcatcher

3:32 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thankyou, that fixed it. I always though that each value in the mail parameters ($to, $subject etc...) had to be enclosed by single quotes, and each iteration of a posted value by '.$value.'

Apparently this isn't the case at all.

Looks like what you are referring to is concatenation, ie the joining of two strings together. I`m guessing you`ve seen somebody else`s code who has used multiple lines joining the data together. Its all down to personal preference, but no, variable values do not need to be enclosed in quotes.

dc

Dexie

12:50 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Just trying to setup something like this, how would it work in practice please? Do you click on a email a friend link and then it takes you to a php page?