Solved

Send simple email from Bluehost hosted site

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please show me easiest post form. 3 31
WordPress Themes 10 34
datetime in sql 6 23
How to convert my query to the proper format? 5 15
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 …
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…
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.

919 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

13 Experts available now in Live!

Get 1:1 Help Now