PDA

View Full Version : PHP Mail() Query


BOAC
18th Jan 2008, 17:13
Trying to use mail() to send to 2 recipients, as mail('[email protected],[email protected]', 'etc', 'etc') but it only ever sends to the first. Wot am I doing wrong please?

BOAC
18th Jan 2008, 19:36
Tried that and no success. The PHP guide actually calls for a ,

flash8
19th Jan 2008, 17:41
<?php
require("class.phpmailer.php");

$mail= new PHPMailer();

$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");

$mail->Body = "shredded wheat sucks";
$mail->send();

?>

BOAC
19th Jan 2008, 19:30
Thanks for reply, F8, but I have a form mail task and cannot see how to fit that in. This is where I am at:

<?php
if($_POST[submit])
{
$message = "Your inside leg:\r\n$_POST[field1]\r\n
Your etc etc;
Your etc etc;

'mail([email protected],[email protected], 'TITLE', $message,'From: email addy');
'echo ' Thank you - Message sent.';
'}
'else
'{
'?>
<form action="" method="post"><br>
<br>
Your inside leg:<br>
<input type="text" size="40" maxlength="40" textarea name="field1"><br><br>
Your etc etc
<input type="submit" name="submit" value="Submit Form">
</form>

Probably a few ;'s and <'s missing in the copying but it works to a single address and it is the multiple email addresses function I seek - or a major rewrite to your code :-(((

flash8
19th Jan 2008, 19:38
Sorry I am no "expert" on these things!

Did you look at: http://uk3.php.net/function.mail ??

It may help - anyhow good luck!

BOAC
19th Jan 2008, 20:59
Yep! It also says "[email protected], [email protected]" but that only seems to send to the first with me.

Its going to be one of those :ugh: answers - I know it......

flash8
19th Jan 2008, 23:00
why not do the following:

on the form to be posted:

<input type="submit" name="submit" value="myvalue">


and on the page it post's to....

$value = $_POST['myvalue']; or $value = $_GET['myvalue']; (cant remember which one you need)

and then the code I mentioned....

anyway something like this... I really am an amateur at coding but I did play around quite a bit a few years back!

mrsurrey
20th Jan 2008, 02:04
Hi BOAC,

try your code with a space between the comma and the second email address.

also put a ' symbol directly before the first email address and another ' symbol directly after the second email address.

finally try saving the email addresses to a variable and then dropping that into the mail function as follows.

$to = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

mail($to, $subject, $message, $headers);
// note no ' sybmols before or after the $to variable





failing that how about just looping your code so that you send the email twice - once to each address?

MrS

bnt
20th Jan 2008, 05:17
Does it matter whether 'single' or "double" quotes are used? I think you should be using single quotes, as per that PHP website. Your first code snippet had no quotes, your second had double quotes...

All the '.' operators are doing, in that PHP code, is concatenating the strings - it shouldn't be a requirement. So it looks to me like you need the addresses surrounded by single quotes, with a comma and a space between them. :8

'mail('[email protected], [email protected]', 'TITLE', $message,'From: email addy');

BOAC
20th Jan 2008, 08:10
Thanks for those ideas - I THINK I've tried them all but will re-do today.

As I thought, had tried all those and it would NOT play ball with multiple addys.

Hats off to MrSurrey for kicking the brain cell into life. Simply put a duplicate

mail('[email protected]' ('[email protected]'), 'TITLE', $message,'From: email addy');

in the script and BINGO. Thanks to all for ideas.

Ian G
21st Jan 2008, 01:52
Does it matter whether 'single' or "double" quotes are used? I think you should be using single quotes, as per that PHP website.

Double quotes will interpolate variables inside the string, single will not.

to parameter needs spaces

http://uk.php.net/manual/en/function.mail.php

If that doesn't work then yes, your workaround will - call mail() twice. Fine except you don't really want to call it too much as automating that function can be construed as spam and you don't want that risk.