tryingtolearn Posted November 5, 2008 Share Posted November 5, 2008 I finally figured out using pear intead of mail() But here is my problem, When using mail() I was sending an image w/ the email to track who opens it etc... Now with pear, I dont have an individual tag to id each email because all the recipients are in 1 array. Is there a way to track the emails? basically I was passing the email address to the url and then when they opened the email I would record the email address to the database. This is what Im using but it only passes the very last recipient as the value for $k include('Mail.php'); include('Mail/mime.php'); // Constructing the email $sender = "from address"; // Your name and email address $track_id = date("D M j Y - g:i a"); $recipients = array(); $query = "SELECT * FROM mailer WHERE mail_receive='Yes'"; $result = @mysql_query ($query); // Run the query. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $recipients[] = $row['mail_email']; // Recipient name and email address } foreach($recipients as $k => $sendto){ $html = "<img src=\"http://www.site.com/tracksent.php?t=$em&e=$k&track_id=$track_id\" width=\"1\" height=\"1\"><br />$message"; } $subject = $em; // Subject for the email $text = 'Your eMail will only accept text messages.To see this message as intended visit this link '; $crlf = "\n"; $headers = array( 'From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject ); // Creating the Mime message $mime = new Mail_mime($crlf); // Setting the body of the email $mime->setTXTBody($text); $mime->setHTMLBody($html); // Add an attachment //$file = "Hello World!"; //$file_name = "Hello text.txt"; //$content_type = "text/plain"; //$mime->addAttachment ($file, $content_type, $file_name, 0); // Set body and headers ready for base mail class $body = $mime->get(); $headers = $mime->headers($headers); // SMTP params $smtp_params["host"] = "smtp.site.com"; // SMTP host $smtp_params["port"] = "587"; $smtp_params["auth"] = true; $smtp_params["username"] = "uname"; $smtp_params["password"] = "upass"; // Sending the email using smtp $mail =& Mail::factory("smtp", $smtp_params); $result = $mail->send($recipients, $headers, $body); if($result) { echo("Your message has been sent!"); echo"<h3>$em was sent to:</h3>"; foreach($recipients as $k => $value){ echo "$value <br />"; $query = "INSERT INTO sent (title, sent_to, track_id, track_key) VALUES ('$em', '$value', '$track_id', '$k')"; $result = @mysql_query ($query); // Run the query. } } else { echo("Your message was not sent: " . $result); } Link to comment https://forums.phpfreaks.com/topic/131480-assign-a-variable-using-mailfactory/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.