Splitting data in text box - send emails to each individualy
Moderator: General Moderators
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Splitting data in text box - send emails to each individualy
I have a 3 text boxes on a form. txtTo, txtSubject and txtBody.
The form also has a submit button. When it is clicked it calls code.php.
The user will specify several email addresses in the text box seperated by semicolons and a space between each.
How can i split these into seperate email addresses and send the email to each one seperately? I do not want each recipient to see everyones email address it is sent to.
Any help is appreciated
Thank you cvmflinchy
The form also has a submit button. When it is clicked it calls code.php.
The user will specify several email addresses in the text box seperated by semicolons and a space between each.
How can i split these into seperate email addresses and send the email to each one seperately? I do not want each recipient to see everyones email address it is sent to.
Any help is appreciated
Thank you cvmflinchy
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
i followed a link by JakeJ in my other topic (which went off topic which is why i made this) and im finally getting there. for some reason though i get this error:
if txtTo only has one email address in and $to1 = $toemail or "my email" then it works but not with this code.
any ideas?
even though this is in my codeerror wrote: Warning: mail() expects parameter 1 to be string, array given in /home/sites/leisure-supplies.co.uk/public_html/admin/newsletter.submit.php on line 30
Newsletter delivery failed... Please try again.
Code: Select all
$toemail = $_REQUEST['txtTo'];
while ( $splitdata = explode('; ', $toemail))
{
$to1 = $splitdata;
line 30: if (mail($to1, $subject1, $body1, $headers1)) {any ideas?
Re: Splitting data in text box - send emails to each individualy
You're not referencing a specific place in the array. Try $to1 = $splitdata[0];
By omitting [0] you're essentially referencing the entire array, not a specific record within.
By omitting [0] you're essentially referencing the entire array, not a specific record within.
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
with $to1 = $splitdata[0]; i just get the message failed notification now from
im trying it with "my email; my email; my email" in the text box (but with my actual email address)
im feel like im so close
Thank you for your help JakeJ I just hope i can clear this last obstacle
Thanks,
CVMFlinchy
Code: Select all
if (mail($to1, $subject1, $body1, $headers1)) {
echo("<p>success message</p>");
} else {
echo("<p>Failed... Please try again.</p>"im feel like im so close
Thank you for your help JakeJ I just hope i can clear this last obstacle
Thanks,
CVMFlinchy
Re: Splitting data in text box - send emails to each individualy
This part of your code doesn't make sense: echo("<p>Failed... Please try again.</p>"
how about: echo "<p> Failed...Please try again.</p>"; }
Perhaps you're just not showing all of you code, but what you entered, isn't valid php code. The success message doesn't need to be in parenthesis either although it doesn't hurt anything.
Maybe you should try echoing out your array to see if the explode command is actually producing anything useful.
how about: echo "<p> Failed...Please try again.</p>"; }
Perhaps you're just not showing all of you code, but what you entered, isn't valid php code. The success message doesn't need to be in parenthesis either although it doesn't hurt anything.
Maybe you should try echoing out your array to see if the explode command is actually producing anything useful.
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
when i echo $splitdata; it comes out as "Array" repeated loads of time but if i echo $splitdata[0]; it shows my email address repeated loads of times. i only put my email in 3 times though.
i changed this for a foreach loop and it displays it 3 times but still wont send the email when i change $to1 to equal the split parts
edit: no i didnt show all my code i just copied and pasted that section to show you where the error message was coming from. i know that bit works because the whole code works if $to1 = "email"
i changed this for a foreach loop and it displays it 3 times but still wont send the email when i change $to1 to equal the split parts
edit: no i didnt show all my code i just copied and pasted that section to show you where the error message was coming from. i know that bit works because the whole code works if $to1 = "email"
Re: Splitting data in text box - send emails to each individualy
not that it should make a difference, but instead of using $to1, just use $splitdata[0] as your variable. No need to reassign it.
So if you do:
So if you do:
Code: Select all
while ( $splitdata = explode('; ', $toemail)) {
echo $splitdata[0],"<br>";
}
What happens?Re: Splitting data in text box - send emails to each individualy
I think the problem is somewhere else you're not showing us
The following worked fine
The following worked fine
Code: Select all
if(isset($_REQUEST['txtTo'])){
$toemail = $_REQUEST['txtTo'];
$subject1="subject";
$body1="body";
$headers="From: me@example.com";
$splitdata = explode('; ', $toemail);
foreach($splitdata as $x){
$to1 = $x;
if (mail($to1, $subject1, $body1, $headers1)) {
echo "<p>success message</p>";
}else{
echo "<p>Failed... Please try again.</p>";
}
}
}
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
ok my whole code is:
when i comment out everything in between from if (mail ...</p>"); } and put echo $to1 . " " . $subect1 . " " . $body1 it displays the email addres then then subject then the body all seperated by a space then immediately shows the next one. so surely the split is successful. its just the mail function isnt picking it up?
Code: Select all
$body = $_REQUEST['txtBody'];
$subject = $_REQUEST['txtSubject'];
$toemail = $_REQUEST['txtTo'];
$splitdata = explode('; ', $toemail);
foreach ( $splitdata as $emailadd)
{
$to1 = $emailadd;
$subject1 = $subject;
$body1 = $body;
$headers1 = "From: my name <name@email.com>";
if (mail($to1, $subject1, $body1, $headers1)) {
echo("<p>Success message.</p>");
} else {
echo("<p>Failed... Please try again.</p>");
}
}Re: Splitting data in text box - send emails to each individualy
Clutching at straws here, but, are you on a Windows server?
http://php.net/manual/en/function.mail.php
http://php.net/manual/en/function.mail.php
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
no i believe it is linux because i have a cgi-bin
also could it be to do with being needed? i will try this code and see if it works instead
also could it be to do with
Code: Select all
# if(isset($_REQUEST['txtTo'])){Re: Splitting data in text box - send emails to each individualy
what would
give you?
Code: Select all
echo mail($to1, $subject1, $body1, $headers1);
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
I dont know about the echo-ing but i got it working with a.hereseys code like this:
only thing is now that means that my database code must have been wrong. using "while" just repeated the emails being sent. i need to change this to a foreach command to be able to send the emails only once per address.
I am using the following code. How would i ammend the while command because the foreach needs ($something as $somethingelse) doesnt it?
NOTE: THIS CODE WORKS AS IT IS. I JUST NEED TO REPLACE THE WHILE COMMAND WITH A FOREACH COMMAND TO STOP IT REPEATING.
Thanks for your help guys its been really useful and helped me loads
i appreciate it
Edit: would i change
to:
Any help is appreciated
Code: Select all
if(isset($_REQUEST['txtTo'])){
$toemail = $_REQUEST['txtTo'];
$subject1= $_REQUEST['txtSubject'];
$body1= $_REQUEST['txtBody'];
$headers1 = "From: name <email>" . "\r\n";
$headers1 .= 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$splitdata = explode('; ', $toemail);
foreach($splitdata as $x){
$to1 = $x;
if (mail($to1, $subject1, $body1, $headers1)) {
echo("<p>success</p>");
} else {
echo("<p>failed... Please try again.</p>");
}
}
}
I am using the following code. How would i ammend the while command because the foreach needs ($something as $somethingelse) doesnt it?
Code: Select all
$q = "SELECT DISTINCT email FROM orders";
$rs = $oAppl->query($q);
while ( $rw = $oAppl->row($rs) )
{
$to1 = $rw["email"];
$subject1 = $_REQUEST['txtSubject'];
$body1 = $_REQUEST['txtBody'];
$headers1 = "From: name <email>" . "\r\n";
$headers1 .= 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (mail($to1, $subject1, $body1, $headers1)) {
echo("<p>success</p>");
} else {
echo("<p>"failed... Please try again.</p>");
}
}
Thanks for your help guys its been really useful and helped me loads
Edit: would i change
Code: Select all
$q = "SELECT DISTINCT email FROM orders";
$rs = $oAppl->query($q);
while ( $rw = $oAppl->row($rs) )
{
$to1 = $rw["email"];
Code: Select all
$q = "SELECT DISTINCT email FROM orders";
$rs = $oAppl->query($q);
$rw = $oAppl->row($rs)
foreach ($rw['email'] as $emailaddress)
{
$to1 = $emailaddress;
-
cvmflinchy
- Forum Newbie
- Posts: 13
- Joined: Sat Feb 06, 2010 12:58 pm
Re: Splitting data in text box - send emails to each individualy
i amended my code to:
is there any way to stop this?
cheers
but for some reason it is sending it to each person twice$q = "SELECT DISTINCT email FROM orders";
$rs = $oAppl->query($q);
while($rw = $oAppl->row($rs)){
foreach($rw as $emailaddress){
$to1 = $rw["email"];
$subject1 = $_REQUEST['txtSubject'];
$body1 = $_REQUEST['txtBody'];
$headers1 = "From: name <email>" . "\r\n";
$headers1 .= 'MIME-Version: 1.0' . "\r\n";
$headers1 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (mail($to1, $subject1, $body1, $headers1)) {
echo("<p>success</p>");
} else {
echo("<p>failed... Please try again.</p>");
}
}
}
is there any way to stop this?
cheers
Re: Splitting data in text box - send emails to each individualy
you don't need a while and a for each loop.