?
Solved

php phpmailer

Posted on 2012-03-29
10
Medium Priority
?
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 1600 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1600 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 1600 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 1600 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

777 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