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?
Printable View
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?
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:
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.:thumb:
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, 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)
Can I use my gmail account?
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
5 Open the file class.smtp.php in phpmailer directoryCode:IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "[email protected]"; //Reply to this email ID
$email="[email protected]"; // 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";
}
?>
6 Paste this code
before the line 104 #connect to the smtp serverCode:$host = "ssl://smtp.gmail.com";
$port = 465;
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.Code:$mail->Username=$_POST['email']
I dont know what to do with the files in phpmailer.
Just put it in a folder in your site.
then in whichever php file you need to send a mail you just say:
Really, just spend an hour or 2 looking at examples and stuff at codeworxtechCode:require_once('../phpmailer/class.phpmailer.php');
Really useful once you got it sorted out, and not that hard as it look.
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.