Help with e-mail splitter script


#1

I’m a fairly new PHP programmer, and I’m learning as I go.

I wrote a script for a client who is an attorney. Since there are multiple attorneys in the firm, I had to provide a way to differentiate who to send form data to.

The script currently seems to run (with warnings) (excuse the look of the site; I didn’t upload the css or images since I only wanted to test the php) but no form data is ever mailed out.

Also, I can’t get the splitter function to work correctly. the script is supposed to use the mail() function and I have the e-mail addresses pointed towards my addresses now for the purpose of testing, but neither address receives an email from the script. Also, regardless of which recipient option I choose, the php output specifies the mail was sent to homer harris (the first option).

Here’s the PHP code: (I’ve replaced the real email addresses with placeholders for privacy reasons)

[code]

<?php /* Tricked Out Email Splitter and sender ##################################### Written by Will Kraft Pagewizard Web Design ###################################### June 4, 2007 Feel free to redistribute and modify this PHP code under the terms of the GPL. */ // this is where the email subject is defined: $subject = "$sendto, there is a new message from the website!"; //define our variables $Name = $_POST[?Name?]; $Address = $_POST[?Address?]; $City = $_POST[?City?]; $Phone = $_POST[?Phone?]; $mailfrom = $_POST[?mailfrom?]; $sendto = $_POST[?sendto?]; //figure out where the mail is supposed to go if ($sendto = "homer") { // ...and send it!!! mail("EMAIL ADDRESS 1", $subject, $Name, $Address, $City, $Phone, $mailfrom); print '

The mail was delivered to Homer Harris.

'; } else if ($sendto = "alfonso") { // If the alfonso button is checked, the mail gets sent here. mail("EMAIL ADDRESS 2", $subject, $Name, $Address, $City, $Phone, $mailfrom); print '

The mail was delivered to Alfonso Oliva.

'; } echo 'Mail delivered successfully.'; ?>

[/code][/url]


#2

the mail() funktion takes the following parameters:
bool mail ( string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters]] )

so u need to combine the massage in one string. e.g.:
[php]$message="$Namen$Addressn$CitynPhone: $Phone";[/php]

the $mailfrom may be put in as a additional header:
[php]$header=“From: $mailfrom”;[/php]
or with name:
[php]$header=“From: “$Name” <$mailfrom>”;[/php]

and then u can send it out:
[php]mail(“EMAIL ADDRESS 1”, $subject, $message, $header);[/php]

P.S. put the definition of the $subject behind the definition of $sendto


#3

That got rid of the warning message, and the email transmits now, but the splitter function still doesn’t work and the email message does not have any of the data in the form fields even though it is referenced in the php script.


#4

Why are you using multiple calls to the mail() function?

[php]
//figure out where the mail is supposed to go

$recipient = “homer@homer.homer”; // DEFAULT RECIPIENT

if ($sendto = “homer”) {
$recipient = “homer@homer.homer”;
$sendto = “Homer Harris”;
} elseif ($sendto = “alfonso”) {
$recipient = “alfonso@alfonso.alfonso”;
$sendto = “Alfonso Oliva”;
}

// …and send it!!!
if ($recipient != “”) {
if (mail($recipient, $subject, $message, $headers)) {
print ‘

The mail was succesfully delivered to $sendto.

’;
} else {
print ‘There was an error while trying to send your mail.’;
}
}
[/php]