PHPMailer?

Hello everyone,

I am trying to set up PHPmailer but this is the first time and I basically have no idea what I am doing! I have read the online tutorials and even watched videos on youtube but still do not understand how to get it working at all. I have added the phpmailer file into my site and put the require 'class.phpmailer.php; into the very start of my page that has the form on it that I want to email. Now when I open up my page it is completely blank? I also do not understand what to put in the settings? Any help is really appreciated.

Here is the code I have put into the start of my page:

[code]<?php
require ‘class.phpmailer.php’;

$mail = new PHPMailer;

$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = ‘smtp1.example.com’; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘jswan’; // SMTP username
$mail->Password = ‘secret’; // SMTP password
$mail->SMTPSecure = ‘tls’; // Enable encryption, ‘ssl’ also accepted
$mail->IsHTML(true); // Set email format to HTML

$mail->From = ‘[email protected]’;
$mail->FromName = ‘Mailer’;
$mail->AddAddress(‘[email protected]’, ‘Josh Adams’); // Add a recipient

$mail->Subject = ‘Here is the subject’;
$mail->Body = ‘This is the HTML message body in bold!’;
$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;
exit;
}

echo ‘Message has been sent’;
?>[/code]

right off the start you need to set up your smtp if that is how you are going to send the mail

also are you having a form? eg. will a user be filling out a form and once they hit submit you receive an email? if so you will have to wrap this inside an “if isset $_POST(submit)” statement and set the vars for the message.

Here is an example of what i mean

$mail->Host = 'smtp1.example.com'; // Specify main and backup server $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'jswan'; // SMTP username $mail->Password = 'secret';

if you dont have an smtp server setup you can use GMAILs free smtp service

[php]<?php

$mail = new PHPMailer(true);

//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = “ssl”; // sets the prefix to the servier
$mail->Host = “smtp.gmail.com”; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = “your-gmail-password”; // GMAIL password
}

//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = “My Subject”;
$mail->Body = “Mail contents”;

try{
$mail->Send();
echo “Success!”;
} catch(Exception $e){
//Something went bad
echo "Fail - " . $mail->ErrorInfo;
}

?>[/php]

also here is a good tutorial for phpmailer

You can also use sendmail by doing something like $mail->isSendmail()

All done :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service