Solved

php phpmailer

Posted on 2012-03-29
10
282 Views
Last Modified: 2012-08-13
I have the following page (attached) which is working on my system. What I am trying to do is to set the page up so that when the page is opened it does not send immediately. I need to put into the body section some php recordset data from a query (again this is ready to go and I should just be able to enter this in the page) and then push a "send" button the send the completed page

The problem I am having is to put the send button on the page
mytest.php
0
Comment
Question by:doctorbill
  • 5
  • 4
10 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 400 total points
ID: 37780715
Here is a mockup.

You need to insert some logic in your script. If the user clicks Submit, then send the mail. Otherwise, run the DB query and show a form.

<?php
if (isset($_REQUEST['SendIt'])) {
    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->Host = "mail.authsmtp.com";  // specify main and backup server
    $mail->SMTPAuth = true;     // turn on SMTP authentication
    $mail->Username = "xxxx";  // SMTP username
    $mail->Password = "xxxx"; // SMTP password

    $mail->From = "info@ticktockit.net";
    $mail->FromName = "TickTockIT";
    $mail->AddAddress("info@ticktockit.net", "Dr Bill Vallins");
    $mail->AddAddress("bvallins@alteredimages.demon.co.uk");                  // name is optional
    $mail->AddReplyTo("info@ticktockit.net", "Information");

    $mail->WordWrap = 50;                                 // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
    $mail->IsHTML(true);                                  // set email format to HTML

    $mail->Subject = "Here is the subject";
    $mail->Body = "This is the HTML message body <b>in bold!</b>";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";

    if (!$mail->Send()) {
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        exit;
    }

    echo "Message has been sent";
    exit();
} else {
    // db query goes here
    // $result = mysql_query("SELECT * FROM table");

    // put the data into a variable
    $text_from_db = "blah blah blah blah";
}
?>

<form method="post">
    Here is the information that will be sent:
    <textarea name="text">
        <?php echo $text_from_db; ?>
    </textarea>
    <input name="SendIt" type="submit"></input>
</form>

Open in new window

0
 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 100 total points
ID: 37780786
Take a look at this tutorial, http://www.phpjabbers.com/make-contact-form-and-send-email-in-php-php21.html

You can do like this.
0
 

Author Comment

by:doctorbill
ID: 37780789
The message that comes through is the following:

$mail->Body = "This is the HTML message body <b>in bold!</b>";

If I get records for the variable "$text_from_db = "blah blah blah blah";" how will this be sent through
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:doctorbill
ID: 37780797
ooops - sorry - I see how it works. I will try with a database record
0
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 400 total points
ID: 37781470
Right, you might also do something like this

$mail->Body = "This is the HTML message body <b>in bold!</b>" . $_REQUEST['text'];
0
 

Author Comment

by:doctorbill
ID: 37786266
Thanks so much for your input - the page is working fine
Just one question - how can I set the data up so that I can use html formating and send this data through as html formated ?

I have attached my latest page constructed from your code
mytest-form-db.php
0
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 400 total points
ID: 37786921
that is a harder question than you think. you can't put markup inside a <textarea>. You might be able to use a text-editor like tinyMCE
0
 

Author Comment

by:doctorbill
ID: 37793468
ok - one last thing:

Sorry to be cheaky but the script is sending an attachment which is pre-defined in terms of location and name - you can see this in the script above

How can I add a file browser so that I can define my own file to  send as an attachment. If I could do this then I don't need to be able to send as formatted html as I can preformat the file as a pdf using other scripts
0
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 400 total points
ID: 37793909
Ok, a couple of things: In your html, you have to have this. Be sure to change the enctype in the form.

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" id="file" /> 

Open in new window


In the php, you can get the file contents with

$_FILES["file"]["tmp_name"]

Open in new window


You can use file_get_contents to read the file
0
 

Author Closing Comment

by:doctorbill
ID: 37807779
Gave me a lot to work on
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MSSQL - Lock Row from reading by other programs 9 61
$_GET call between URL 3 43
PHP Web Development 6 27
xml with php question 5 36
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question