Jump to content

Help creating form for Email script


zacthespack

Recommended Posts

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       = "zac@zpwebsites.com";
$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("zacthespack@gmail.com", "John Doe");

$mail->AddAttachment("uploads/AleMail.pdf");             // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

 

Link to comment
Share on other sites

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     = "zac@zpwebsites.com";
$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.