fwstealer
asked on
send php email
I'm trying to send an email from php and I'm not having much luck. I'm using Vista, Apache and PHP. Below is my sample code. I even tried the code on a Linux server that is capable of send emails and had no luck. Any suggestions?
other php code above
//send email
$mailcheck = spamcheck($txtbxEmail);
if ($mailcheck==FALSE)
{
echo "Invalid input; mail not sent";
}
else
{//send email
$mailTo = $txtbxEmail;
$mailFrom = "sales@me.com";
$mailSubject = "test";
$mailMessage = "hello test";
$headers = "From: $mailFrom";
$headers .= "BCC: admin@me.com\r\n";
try
{
$mailsend = mail($mailTo, $mailSubject, $mailMessage, $headers);
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
if ($mailsend == 1)
{
echo "mail sent <br />";
}
else
{
echo "mail not sent <br />"; // I get this all the time.
}
}
}
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
ASKER
i tried phpmailer and got an instantiation error - couldn't connect
ASKER
blows up here
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail = new PHPMailer(); // defaults to using php "mail()"
it's a tutorial here on how to configure PHPMailer
http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html
http://www.askapache.com/php/phpfreaks-eric-rosebrocks-phpmailer-tutorial.html
ASKER
wow that seems complex just to send an email
usualy the hosting company has all this configured. but you want to make it work from your local machine.
so you need to make the configurations :D
so you need to make the configurations :D
ASKER
right; what is need to work from the hosting company?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Remember to change the email from and the $email and 'Reply-To' lines to make them variables so you can set them elsewhere on another page if you like. I just tested the code and recieved an email by putting my info in the right sections. Let me know how it goes ok.
Cheers
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how do i bcc to an email address?
ASKER
i noticed in message there are no line breaks. How do I get the copy to break on separate lines?
ASKER
nervermind on the bcc - figured it out
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
usualy this it's working when you put your script on a server with a domain
for the localhost you have to try to install smtp server i think
or use phpmailer http://sourceforge.net/projects/phpmailer
after that you have to make changes on php.ini for the smtp setings