zacthespack Posted October 17, 2010 Share Posted October 17, 2010 I am using a simple email script called PHPmailer which works great but i would like to create a form so a user can input what the text for the email should be along with the subject from texts boxes, i also need the script to connect to a mysql database to get a list of email address to send to. Then once the user presses the send button the email is sent out to everyone in the database. Can anyone help me? <?php include_once('class.phpmailer.php'); $mail = new PHPMailer(); $body = eregi_replace("[\]",'',$body); $mail->IsSendmail(); // telling the class to use SendMail transport $mail->From = "[email protected]"; $mail->FromName = "First Last"; $mail->Subject = "PHPMailer Test Subject via smtp"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress("[email protected]", "John Doe"); $mail->AddAttachment("uploads/AleMail.pdf"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> Link to comment https://forums.phpfreaks.com/topic/216087-help-creating-form-for-email-script/ Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2010 Share Posted October 17, 2010 Can you post the form code and the database code? Link to comment https://forums.phpfreaks.com/topic/216087-help-creating-form-for-email-script/#findComment-1123034 Share on other sites More sharing options...
zacthespack Posted October 17, 2010 Author Share Posted October 17, 2010 I dont have the Form or database code thats what i need Link to comment https://forums.phpfreaks.com/topic/216087-help-creating-form-for-email-script/#findComment-1123035 Share on other sites More sharing options...
zacthespack Posted October 17, 2010 Author Share Posted October 17, 2010 Ok i have worked out a script to connect to the database and get the mailing list i just need help creating the html form or at least how to create a button from another page that when pressed runs this script? <?php require("class.phpmailer.php"); $mail = new phpmailer(); $mail->From = "[email protected]"; $mail->FromName = "Zac"; $mail->Subject = "Here is the subject"; $db_table = "easy_newsletter"; @MYSQL_CONNECT("localhost","zpwebsi1_zac","powell"); @mysql_select_db("zpwebsi1_news"); $query = "SELECT name, email FROM $db_table ORDER BY email ASC;"; $result = @MYSQL_QUERY($query); while ($row = mysql_fetch_array ($result)) { // HTML body $body = "Hello <font size=\"4\">" . $row["name"] . "</font>, <p>"; $body .= "<i>Your</i> personal photograph to this message.<p>"; $body .= "Sincerely, <br>"; $body .= "phpmailer List manager"; // Plain text body (for mail clients that cannot read HTML) $text_body = "Hello " . $row["name"] . ", \n\n"; $text_body .= "Your personal photograph to this message.\n\n"; $text_body .= "Sincerely, \n"; $text_body .= "phpmailer List manager"; $mail->Body = $body; $mail->AltBody = $text_body; $mail->AddAddress($row["email"], $row["name"]); $mail->AddStringAttachment = "uploads/AleMail.pdf"; if(!$mail->Send()) echo "There has been a mail error sending to " . $row["email"] . "<br>"; } else { echo "Message sent!"; } // Clear all addresses and attachments for next loop $mail->ClearAddresses(); $mail->ClearAttachments(); } ?> Link to comment https://forums.phpfreaks.com/topic/216087-help-creating-form-for-email-script/#findComment-1123057 Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2010 Share Posted October 17, 2010 http://www.phpf1.com/tutorial/php-form.html Link to comment https://forums.phpfreaks.com/topic/216087-help-creating-form-for-email-script/#findComment-1123074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.