Solved

php phpmailer

Posted on 2012-03-29
10
283 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

717 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