Wikiposts
Search

Notices
Computer/Internet Issues & Troubleshooting Anyone with questions about the terribly complex world of computers or the internet should try here. NOT FOR REPORTING ISSUES WITH PPRuNe FORUMS! Please use the subforum "PPRuNe Problems or Queries."

PHP Mail() Query

Thread Tools
 
Search this Thread
 
Old 18th January 2008 | 17:13
  #1 (permalink)  
Thread Starter
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
PHP Mail() Query

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 is offline  
Reply
Old 18th January 2008 | 19:36
  #2 (permalink)  
Thread Starter
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
Tried that and no success. The PHP guide actually calls for a ,
BOAC is offline  
Reply
Old 19th January 2008 | 17:41
  #3 (permalink)  
20 Anniversary
 
Joined: May 2004
Aviation Qualifications: CPL
Posts: 965
Likes: 46
From: Ташкент
<?php
require("class.phpmailer.php");

$mail= new PHPMailer();

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


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

?>
flash8 is offline  
Reply
Old 19th January 2008 | 19:30
  #4 (permalink)  
Thread Starter
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
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 :-(((
BOAC is offline  
Reply
Old 19th January 2008 | 19:38
  #5 (permalink)  
20 Anniversary
 
Joined: May 2004
Aviation Qualifications: CPL
Posts: 965
Likes: 46
From: Ташкент
Sorry I am no "expert" on these things!

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

It may help - anyhow good luck!
flash8 is offline  
Reply
Old 19th January 2008 | 20:59
  #6 (permalink)  
Thread Starter
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
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 answers - I know it......
BOAC is offline  
Reply
Old 19th January 2008 | 23:00
  #7 (permalink)  
20 Anniversary
 
Joined: May 2004
Aviation Qualifications: CPL
Posts: 965
Likes: 46
From: Ташкент
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!
flash8 is offline  
Reply
Old 20th January 2008 | 02:04
  #8 (permalink)  
 
Joined: Aug 2002
Posts: 181
Likes: 0
From: Surrey
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

Last edited by mrsurrey; 20th January 2008 at 02:16.
mrsurrey is offline  
Reply
Old 20th January 2008 | 05:17
  #9 (permalink)  
bnt
15 Anniversary
 
Joined: Feb 2007
Posts: 755
Likes: 26
From: Dublin, Ireland. (No, I just live here.)
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.

'mail('[email protected], [email protected]', 'TITLE', $message,'From: email addy');
bnt is offline  
Reply
Old 20th January 2008 | 08:10
  #10 (permalink)  
Thread Starter
Per Ardua ad Astraeus
 
Joined: Mar 2000
Posts: 18,575
Likes: 4
From: UK
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]', 'TITLE', $message,'From: email addy');

in the script and BINGO. Thanks to all for ideas.
BOAC is offline  
Reply
Old 21st January 2008 | 01:52
  #11 (permalink)  
 
Joined: Jan 2008
Posts: 6
Likes: 0
From: Merseyside
Originally Posted by bnt
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.
Ian G is offline  
Reply

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service

Copyright © 2026 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.