foreach array delimited by qualifer
Right now, i am reading in an array and doing a foreach loop on the array to run a set script, in this case, PHPmail. In that array, I have it working 100% to send the array to update the subject file. I want to update the code so that the script will still run on one foreach loop but will read in two separate strings (almost in effect in parallel) that will be delimited by a character... for example the character ~ ...
so, assume "list" had the following SUBJECT Goes here~/home/username/filename SUBJECT went here~/home/username2/filename2
Right now, the code would read in each line above as SubjectLiner and send the enter line in the subject.
I want the PHP to break these apart so that when the php is ran it would pull these two apart in one sequence. Right now, it works great without the ~ or the attachement component. (or the one many works just fine... i want to get the one to one working)..
so the desired result would be on the first pass SubjectLiner would be "SUBJECT Goes here" AttachmentLiner would be "/home/username/filename" and then on the second pass: SubjectLiner would be "SUBJECT went here" AttachmentLiner would be "/home/username2/filename2
below the is code I am testing.. I dont know how delimit based on a qualifier ~ in my example above.. and then have the two strings processed.
This same thing can be accomplished with two separate files that are matched line for line.. but the risk goes exponentially up to send the wrong attachment.
At the end of the day, I need to send a routine email to the same recipient (a server) that has a different Subject (w/ spaces and ;s) and different attachements. I have it 85% beaten. It is the dual information per line that is needed. Super appreciate any comments. thx.
<?php
require("class.phpmailer.php");
$addylist = file("list"); // Subject line feeder.
foreach($addylist as $SubjectLiner)
{
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "username"; // SMTP username
$mail->Password = "yourpassword"; // SMTP password
$mail->From = "username";
$mail->FromName = "username";
$mail->AddReplyTo("FromAddy", "From Name");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->AddAddress("ToAddy", "To Name");
$mail->Body = "";
$mail->AltBody = "";
$mail->Subject = $SubjectLiner;
$mail->AddAttachment("$AttachmentLiner"); // add attachments
if(!$mail->Send())
{
echo "Message could not be sent. <p&开发者_如何转开发gt;";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
}
?>
Explode the $SubjectLiner
and use the two parts:
<?php
require("class.phpmailer.php");
$addylist = file("list"); // Subject line feeder.
foreach($addylist as $SubjectLiner)
{
$SubjectLiner = explode("~",$SubjectLiner);
$subject = $SubjectLiner[0];
$attachment = $SubjectLiner[1];
//$mail = .... Same as in your example
$mail->Subject = $subject;
$mail->AddAttachment($attachment); // add attachments
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
}
?>
Is there a specific question here? or you are glad you did it and want the world to see it? :))
However, you have a missing quote here:
$mail->AddReplyTo("FromAddy, "From Name");
Replace that with
$mail->AddReplyTo("FromAddy", "From Name");
精彩评论