Trevor Local
asked on
Website PHP mailer form not working - (Linux server)
Hi - I have a website with a contact page, and have a PHP form. I have input the $recip field with the email address I'd like the mail to go to, but it's not working. Not sure what to check or what else I would need to add/subtract.
Any ideas?
code below:
Any ideas?
code below:
<?php
// list all vars to be expected from the movie
$vars = array("contact_name", "contact_email", "contact_message");
// and import them into the script
foreach($vars as $var)
if(isset($_POST[$var]))
$$var = $_POST[$var];
else
$$var = '';
// where to send it
// remove or configure one of the two code blocks
// otherwise your mail will be sent to johnnybegood@hotmail.com :)
// ***** or one fixed recipient ******
$recip = "info@mydomain.info";
//**** end fixed recipient *******
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=utf-8\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: photographer@domain.com";
// build up message
// this code for any multiline text fields
$message = str_replace("\r", "\n", $contact_message);
// info vars
$sender = $_SERVER[REMOTE_ADDR];
// you can rearrange this - just do not add or remove quotes
$mailbody = "Contact form send by:
Name: $contact_name
Email: $contact_email
Message:
$contact_message
-------
sender's ip: $sender";
mail($recip, "Contact form", $mailbody, $headers);
// and tell visitor
print "&status=sent_ok";
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I changed the photographer@domain.com to webform@mydomain.info - does that need to be an actual mailbox (webform)?
I loaded a php file with phpinfo() to my server root and browsed to it, and it only displays "phpinfo()"
I loaded a php file with phpinfo() to my server root and browsed to it, and it only displays "phpinfo()"
It needs to be:
<?php phpinfo(); ?> to display correctly.
I don't believe it has to be an actual mailbox, but the domain should be the same server. It wouldn't hurt to try it with an active box, though.
<?php phpinfo(); ?> to display correctly.
I don't believe it has to be an actual mailbox, but the domain should be the same server. It wouldn't hurt to try it with an active box, though.
ASKER
I created a mailbox for webform.
OK, I can now see the config variables. It says my php.ini is in /etc directory, but I can't see that directory.
In the config I notice it has: sendmail_from "no value"
OK, I can now see the config variables. It says my php.ini is in /etc directory, but I can't see that directory.
In the config I notice it has: sendmail_from "no value"
sendmail_from being empty is OK - you're defining the from field in the mail() anyway.
we care more about sendmail_path....
try this on it's own page:
<?php
$my_em = "your_name@domain.com"; // replace this with your working e-mail address
$serv_em = "website@serverdomain.com" ; // replace this with an address on your server domain name
mail($my_em, "TEST", "TEST", "From: ".$serv_em);
?>
And see if that works at all.
we care more about sendmail_path....
try this on it's own page:
<?php
$my_em = "your_name@domain.com"; // replace this with your working e-mail address
$serv_em = "website@serverdomain.com"
mail($my_em, "TEST", "TEST", "From: ".$serv_em);
?>
And see if that works at all.
ASKER
it says my sendmail_path is /usr/sbin/sendmail -t -i
i created that php file and uploaded to my root directory, then browsed to it. I get an empty page.
i created that php file and uploaded to my root directory, then browsed to it. I get an empty page.
ASKER
when I browse to my send_email.php, I get &status=sent_ok
ok - since you got an empty page, I assume no error was returned. Did you receive your test e-mail?
ASKER
no I didn't get the test mail.
ASKER
i was on with Brinkster (host) tech support and they created a test php form, which works when I browse to it (code below) - so it seems my code is missing something?
<?PHP
require("/sites/yuma3/xxxxx/home/includes/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mymail.brinkster.com";
$mail->SMTPAuth = true;
$mail->Username = "info@mydomain.info";
$mail->Password = "password";
$mail->From = "info@mydomain.info";
$mail->FromName = "Dustin";
$mail->AddAddress("info@mydomain.info", "Webform");
$mail->IsHTML(true);
$mail->Subject = "Test message sent using the PHPMailer component";
$mail->Body = "This is a test message.";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you are correct! I just got on with another tech support and he finally told me that in fact mail() is disabled. would have been nice to know that to begin with!
so it looks like I need a new script.....hehh
so it looks like I need a new script.....hehh
ASKER
so I have a new code, and it works when I browse to it (sends an email to the inbox), but it doesn't work through Flash on my contact page. (code below)
now I'm stumped again! any ideas?
now I'm stumped again! any ideas?
<?php
// list all vars to be expected from the movie
$vars = array("contact_name", "contact_email", "contact_message");
// and import them into the script
foreach($vars as $var)
if(isset($_POST[$var]))
$$var = $_POST[$var];
else
$$var = '';
// build up message
// this code for any multiline text fields
$message = str_replace("\r", "\n", $contact_message);
// info vars
$sender = $_SERVER[REMOTE_ADDR];
// you can rearrange this - just do not add or remove quotes
$mailbody = "Contact form sent by:
Name: $contact_name
Email: $contact_email
Message:
$contact_message
-------
sender's ip: $sender";
require_once("/sites/yuma3/xxxxx/home/includes/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mymail.brinkster.com";
$mail->SMTPAuth = true;
$mail->Username = "info@mydomain.info";
$mail->Password = "password";
//$mail->From = "info@usedcardepot.info";
$contact_email = preg_replace("/[^a-zA-Z0-9_\.\-]+/", '', $contact_email);
$contact_name = preg_replace("/[^a-zA-Z0-9_\.\-\s]+/", '', $contact_name);
//$mail->FromName = "Test";
$mail->From = $contact_email;
$mail->FromName = $contact_name;
$mail->AddAddress("info@mydomain.info", "Webform");
$mail->IsHTML(true);
$mail->Subject = "Contact Form";
$mail->Body = $mailbody;
if(!$mail->Send())
{
print "&status=sent_error";
// echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
print "&status=sent_ok";
}
That's another roadblock for me. I don't work with flash. You might need to ask in the flash zone.
ASKER
I'll start there. Where is the mail server configuration? I know mail works, because I can send/receive mail from the account I'm trying to use on the contact page.
And is the "photographer@domain.com" just a placeholder? I don't know what that mailbox is.
thanks!