Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

php phpmailer

Posted on 2012-03-29
10
Medium Priority
?
288 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

650 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