PDA

Click to See Complete Forum and Search --> : Silly email question


xxarmoxx
Nov 18th, 2008, 03:35 PM
I am using WAMP, how can I test sending emails with PHP? Is it possible or do I need to be on a legit webhost like godaddy?

the182guy
Nov 18th, 2008, 05:28 PM
No you don't need to be on a webhost.

In your php.ini configuration file, there are settings for the outgoing mail server (SMTP). Open up your php.ini and look for these settings:


[mail function]
SMTP = smtp.somewhere.com
sendmail_from = me@here.com


You should be able to test mail in PHP using your Internet Service Providers SMTP server, and your email account with them.

I don't know if you know how to actually send the mail in a script but the easiest way is the mail() function (http://uk3.php.net/mail).:thumb:

StrangerInBeijing
Nov 19th, 2008, 11:15 AM
Guess fixed, but when I started with php (using wamp also) there was a bug (or I was mistaken) with mail() on a windows server.

So I got used to using phpmailer (http://phpmailer.codeworxtech.com/), and still use it. Very usefull and easy to use.

Off course you first have to do what theguy said. Unless you allready set that up right when installing wamp server (guess u do use it)

xxarmoxx
Nov 24th, 2008, 07:28 PM
Can I use my gmail account?

StrangerInBeijing
Nov 24th, 2008, 07:36 PM
1 Download PHPMailer from http://phpmailer.sourceforge.net
2 Extract to folder phpmailer
3 Create a file email.php
4 Paste this code and change the values as you need

IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
5 Open the file class.smtp.php in phpmailer directory
6 Paste this code
$host = "ssl://smtp.gmail.com";
$port = 465;
before the line 104 #connect to the smtp server
Hint: Search for #connect
7 Open this page in browser and it will send the email using GMail.

Hint: When you want to email the details from a form, set the variables using the form variables.
eg. $mail->Username=$_POST['email']

xxarmoxx
Nov 24th, 2008, 10:54 PM
I dont know what to do with the files in phpmailer.

StrangerInBeijing
Nov 24th, 2008, 11:00 PM
Just put it in a folder in your site.
then in whichever php file you need to send a mail you just say:
require_once('../phpmailer/class.phpmailer.php');

Really, just spend an hour or 2 looking at examples and stuff at codeworxtech (http://phpmailer.codeworxtech.com/index.php?pg=examples)
Really useful once you got it sorted out, and not that hard as it look.

buzzby
Dec 15th, 2008, 05:51 AM
i have tried using this script but it falls down at the isSMTP(); line. i think thats the very first line of the script. how do i counteract this? this is the 3rd script i am using. none of which seem to work on my IIS server. i need to input a username and password of the server in order for the server to send the emails thru.