Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Send simple email from Bluehost hosted site

Posted on 2015-02-21
11
Medium Priority
?
405 Views
Last Modified: 2015-02-22
I wish, using PHP, to send an email with an attachment.

The site is hosted on BlueHost.

I tried PHPMailer but I don't know how to "include" what needs to be included... or rather where the file is located to include.
0
Comment
Question by:classnet
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 1000 total points
ID: 40623537
You just need to use the AddAttachment() method:

AddAttachment("phpmailer.gif");

That assumes that bluehost allows attachments to be send with emails.

Cd&
0
 
LVL 14

Expert Comment

by:quizwedge
ID: 40623546
Check out PHPMailer's read me for a code example (https://github.com/Synchro/PHPMailer/blob/master/README.md#a-simple-example)

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$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.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

Open in new window

0
 

Author Comment

by:classnet
ID: 40623549
COBOLdinosaur... what I meant was that I cannot get PHPMailer to work at all.  So, I am using "mail" but don't know how to add an attachment.

To use PHPMailer you need to "include" a class that I cannot locate.
0
Independent Software Vendors: 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:classnet
ID: 40623552
Cannot execute:

require 'PHPMailerAutoload.php';

Where is PHPMailerAutoload.php located?
0
 
LVL 14

Assisted Solution

by:quizwedge
quizwedge earned 1000 total points
ID: 40623560
Wish I had kept my original comment... I thought I had misread and thought it was only about the attachment. Check out PHPMailer's install docs (https://github.com/Synchro/PHPMailer/blob/master/README.md#installation--loading)

Installation & loading

PHPMailer is available via Composer/Packagist. Alternatively, just copy the contents of the PHPMailer folder into somewhere that's in your PHP include_path setting. If you don't speak git or just want a tarball, click the 'zip' button at the top of the page in GitHub.

PHPMailer provides an SPL-compatible autoloader, and that is the preferred way of loading the library - just require '/path/to/PHPMailerAutoload.php'; and everything should work. The autoloader does not throw errors if it can't find classes so it prepends itself to the SPL list, allowing your own (or your framework's) autoloader to catch errors. SPL autoloading was introduced in PHP 5.1.0, so if you are using a version older than that you will need to require/include each class manually.

PHPMailer does not declare a namespace because namespaces were only introduced in PHP 5.3.

Minimal installation

While installing the entire package manually or with composer is simple, convenient and reliable, you may want to include only vital files in your project. At the very least you will need class.phpmailer.php. If you're using SMTP, you'll need class.smtp.php, and if you're using POP-before SMTP, you'll need class.pop3.php. For all of these, we recommend you use the autoloader too as otherwise you will either have to require all classes manually or use some other autoloader. You can skip the language folder if you're not showing errors to users and can make do with English-only errors. You may need the additional classes in the extras folder if you are using those features, including NTLM authentication and ics generation.
0
 
LVL 14

Expert Comment

by:quizwedge
ID: 40623563
Short answer on that is that PHPMailerAutoload.php is wherever you put it. You'll need to download PHPMailer and put it in a directory and require wherever you put PHPMailerAutoload.php.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40623564
If you still have a problem finding it, Then you should open a ticket with Bluehost to find out if they have it installed and where it is located.

Cd&
0
 

Author Closing Comment

by:classnet
ID: 40623576
Thanks!  Got it working!
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 40623941
You've pointed the links at my personal fork - please use the official PHPMailer repo at https://github.com/PHPMailer/PHPMailer
0
 
LVL 14

Expert Comment

by:quizwedge
ID: 40624388
Thanks @Squinky. Might want to let http://phpmailer.worxware.com/ know to update their page. They're the first Google result and have the official version of PHPMailer as your personal fork.
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 40624497
I know, I've asked Andy a couple of times, but I know he's been very unwell.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

824 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