Solved

php phpmailer

Posted on 2012-03-29
10
278 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now