Send simple email from Bluehost hosted site

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.
classnetAsked:
Who is Participating?
 
COBOLdinosaurConnect With a Mentor Commented:
You just need to use the AddAttachment() method:

AddAttachment("phpmailer.gif");

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

Cd&
0
 
quizwedgeCommented:
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
 
classnetAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
classnetAuthor Commented:
Cannot execute:

require 'PHPMailerAutoload.php';

Where is PHPMailerAutoload.php located?
0
 
quizwedgeConnect With a Mentor Commented:
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
 
quizwedgeCommented:
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
 
COBOLdinosaurCommented:
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
 
classnetAuthor Commented:
Thanks!  Got it working!
0
 
Marcus BointonCommented:
You've pointed the links at my personal fork - please use the official PHPMailer repo at https://github.com/PHPMailer/PHPMailer
0
 
quizwedgeCommented:
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
 
Marcus BointonCommented:
I know, I've asked Andy a couple of times, but I know he's been very unwell.
0
All Courses

From novice to tech pro — start learning today.