Hi there

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Klaire
Forum Newbie
Posts: 5
Joined: Fri May 26, 2006 9:17 am

Hi there

Post by Klaire »

I have been working on sending emails...i am trying to send for emails at one go but unfortunately it is not letting me....the code itself allows me to send 2 only...can somebody tell me why it is doing so....the following is the code

Code: Select all

if($error) {
?>
      </p>
      <p><span class="style1"><b>The following information is required</b><br />
        <?php echo $error;
 ?></span> <a href="#" onClick="history.go(-1)">Please correct before submitting</a></span>
        <?php
}
else 
{

$browser = $HTTP_USER_AGENT;
$ip = $REMOTE_ADDR;

// format message
$message = "Online-Form Response for $recipientname:

Title: $Title
Surname: $Surname
Name: $Name 
DOB: $DOB
Telephone_Number: $Telephone_Number
Mobile_Number: $Mobile_Number
Email: $Email
Availability: $Availability
Available_weekends_Yes: $Av_wk_yes
Available_weekends_No: $Av_wk_no
Available_Holidays_Yes: $Av_hol_yes
Available_Holidays_No: $Av_hol_no
alt_email: $alt_email
native_lang: $native_lang
trans_lang: $trans_lang
inter_lang: $inter_lang
select_trans: $select_trans
select_qual: $select_qual
Comments_inter: $Comments_inter
Name: $Name3
Company: $Company3
Email_Comp: $Email_Comp3
Name: $Name2
Company2: $Company2
Email_Comp2: $Email_Comp2
Notes: $Notes 




-----------------------------

Browser: $browser
User IP: $ip";

$messageref = "Dear $Name3,


We have just received an application from $Title $Name $Surname to register as a translator for . The translator gave your details as a reference, would you please click on the following link and complete the short questionnaire:

http://www.miriamchristine.com/test/Questionnaire.php


Your answers will be kept in the strictest confidence and your email address will never be passed on to third parties.

If you have any questions regarding this matter, please reply to this email and we'll be glad to answer any queries you might have.


$messageusref = "A reference request for $Title $Name $Surname has been sent to the following:
 
$Name3 and $Email_Comp3
$Name2 and $Email_Comp2";



// send mail and print success message
mail($recipientemail,"$subject","$message","From: $Name <$Email>");


if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}

echo "$thanks";
}
} 
else {
?>
Thanks a lot
Claire
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Maybe because you are only telling it to run the mail() function 2 times not 4


This will send the same message 4 times:

Code: Select all

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Klaire wrote:

Code: Select all

<?php
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
?>
You know you are sending the exact some email twice to the same person with this code, right? Also, when posting PHP code, please wrap your code in

Code: Select all

tags, not

Code: Select all

tags. It makes it a little easier to read.
Klaire
Forum Newbie
Posts: 5
Joined: Fri May 26, 2006 9:17 am

Response webform problem

Post by Klaire »

Hi there....

I tried putting 4 mail functions like you asked me to but still its sending 2 emails. The wierd thing is that is only 2 mails functions working in the form.

Let me explain you more in detail:

1st try : response first 2 emails

Code: Select all

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email_Comp3,"$autosubject","$messageref3","From: $recipientname <$recipientemail>");
mail($Email_Comp2,"$autosubject","$messageref2","From: $recipientname <$recipientemail>");
mail($recipientemail,"$subjectref","$messageusref","From: $Name <$Email>");
mail($recipientemail,"$subject","$message","From: $Name <$Email>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");

}

echo "$thanks";
}
2nd try : response first 2 emails

Code: Select all

mail($Email_Comp3,"$autosubject","$messageref3","From: $recipientname <$recipientemail>");
mail($Email_Comp2,"$autosubject","$messageref2","From: $recipientname <$recipientemail>");

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($recipientemail,"$subjectref","$messageusref","From: $Name <$Email>");
mail($recipientemail,"$subject","$message","From: $Name <$Email>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");

}

echo "$thanks";
}
3rd try : response first 2 emails (second autoresponse)

Code: Select all

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email_Comp3,"$autosubject","$messageref3","From: $recipientname <$recipientemail>");
mail($Email_Comp2,"$autosubject","$messageref2","From: $recipientname <$recipientemail>");


}

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($recipientemail,"$subjectref","$messageusref","From: $Name <$Email>");
mail($recipientemail,"$subject","$message","From: $Name <$Email>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");

}

echo "$thanks";
}

Do you think that its all because i have one autoresponse and one recipientemail?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I would be willing to bet there is something preventing mail from making a connection with the SMTP server. Try a little error checking in your code. And you might also want to remove the double quotes (") from around your vars in the mail function.

Code: Select all

<?php
if ($autoresponse == "yes") {
    $autosubject = stripslashes($autosubject);
    $automessage = stripslashes($automessage);
    if (!mail($Email_Comp3, $autosubject, $messageref3, "From: $recipientname <$recipientemail>")) echo "Message 1 Failed...<br />";
    if (!mail($Email_Comp2, $autosubject, $messageref2, "From: $recipientname <$recipientemail>")) echo "Message 2 Failed...<br />";
    if (!mail($recipientemail, $subjectref, $messageusref, "From: $Name <$Email>")) echo "Message 3 Failed...<br />";
    if (!mail($recipientemail, $subject, $message, "From: $Name <$Email>")) echo "Message 4 Failed...<br />";
    if (!mail($Email, $autosubject, $automessage, "From: $recipientname <$recipientemail>")) echo "Message 5 Failed...<br />";;
}
?>
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: Response webform problem

Post by aerodromoi »

Klaire wrote:

Code: Select all

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($Email_Comp3,"$autosubject","$messageref3","From: $recipientname <$recipientemail>");
mail($Email_Comp2,"$autosubject","$messageref2","From: $recipientname <$recipientemail>");


}

if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($recipientemail,"$subjectref","$messageusref","From: $Name <$Email>");
mail($recipientemail,"$subject","$message","From: $Name <$Email>");
mail($Email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");

}

echo "$thanks";
}

Do you think that its all because i have one autoresponse and one recipientemail?
Why do you use two separate if statements, both checking whether $autoresponse is set to "yes"? Idem for the stripslashes part. (just being curious)

Provided that $autoresponse is set to yes and provided that you've got four working email addresses and four strings containing them ($recipientemail, $Email, $Email_Comp3 and $Email_Comp2) you should get five emails.

btw: I'd rather store all the email addresses in an array and loop through it rather than pasting the mail function x times in the script.

aerodromoi
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I think he was posting variations of his code to show what was not working. And I was thinking a loop through an array would work, until I looked at the items being mailed. Every one of the mails is sending something different, so it is not a canned message get sent to multiple recipients, it is multiple mails be sent.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

Everah wrote:I think he was posting variations of his code to show what was not working. And I was thinking a loop through an array would work, until I looked at the items being mailed. Every one of the mails is sending something different, so it is not a canned message get sent to multiple recipients, it is multiple mails be sent.
That doesn't rule out an array. I'd take the email address as the key and the string for the body as the value.
Using a for loop and array_keys and array_values you can basically send anything.

aerodromoi
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I agree with you. Although I would suspect that the reason his emails are not sending to the other two addresses has something to do with the mail not being accepted. But I would agree that there are more efficient ways of send multiple mails.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Everah wrote:But I would agree that there are more efficient ways of send multiple mails.
/swoops in cape trailing 'n' all: http://www.swiftmailer.org/documentation/51#view
/swoops away again

:)
Last edited by Chris Corbyn on Mon Jun 05, 2006 11:55 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Who was that caped codesader :?: :!: :idea:
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

d11wtq wrote:
Everah wrote:But I would agree that there are more efficient ways of send multiple mails.
/swoops in cape trailing 'n' all: http://www.swiftmailer.org/documentation/51#view
/swoops away again

:)
Even codesader wouldn't know whether some of the variables (supposedly) containing the email addresses are empty or not ;)

Code: Select all

if(!$script_complete) echo "guess";
aerodromoi
Post Reply