Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 803
  • Last Modified:

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:
<?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";
?>

Open in new window

0
Trevor Local
Asked:
Trevor Local
  • 9
  • 5
  • 3
3 Solutions
 
k_dietzCommented:
Assuming the mail server information is setup correctly in the php configuration, try removing all of the header variables and leaving only "From: photographer@domain.com".  Then, make sure all of the variables are populating correctly with an echo statement right before the mail() line, and then try to see if the mail() function works at all using information you know works:

mail("youremail@domain.com","Subject Test", "Body Test", "From: website@domain.com");  

If this line doesn't work - you know that the e-mail server info isn't setup correctly on the server (after replacing domain.com with your domain, of course).
0
 
Trevor LocalAuthor Commented:
"Assuming the mail server information is setup correctly in the php configuration"

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!
0
 
k_dietzCommented:
photographer@domain.com is what you listed as the From: address.  If the from address is incorrect, that could be why it's not working - the from domain should be the same domain that the server is on.

You can find your PHP.INI file (the configuration) easily by loading a php page with phpinfo() in it.  phpinfo() will display all of your configuration variables:

Loaded Configuration File will tell you the location.


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Trevor LocalAuthor Commented:
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()"
0
 
k_dietzCommented:
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.
0
 
Trevor LocalAuthor Commented:
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"
0
 
k_dietzCommented:
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.

0
 
Trevor LocalAuthor Commented:
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.
0
 
Trevor LocalAuthor Commented:
when I browse to my send_email.php, I get &status=sent_ok
0
 
k_dietzCommented:
ok - since you got an empty page, I assume no error was returned. Did you receive your test e-mail?
0
 
Trevor LocalAuthor Commented:
no I didn't get the test mail.
0
 
Trevor LocalAuthor Commented:
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";
 
?>

Open in new window

0
 
Hube02Commented:
By looking at the code that your host povided, it is safe to assume that they have disabled the mail() function in PHP.

They are using a class (class.phpmailer.php: http://phpmailer.codeworxtech.com/index.php)

and they are using SMTP to send the email. You will either need to use the class or do the SMTP mail yourself.

As far as how to do it yourself, I have never needed to use it, and don't know how. And I would not be much help with PHPmailer.
0
 
Trevor LocalAuthor Commented:
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
0
 
Trevor LocalAuthor Commented:
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?
<?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";
 
}

Open in new window

0
 
Hube02Commented:
That's another roadblock for me. I don't work with flash. You might need to ask in the flash zone.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 9
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now