Solved

Send simple email from Bluehost hosted site

Posted on 2015-02-21
11
219 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 250 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

679 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