Omnimaga

General Discussion => Technology and Development => Web Programming and Design => Topic started by: flyingfisch on November 02, 2012, 02:13:45 pm

Title: mail() not working?
Post by: flyingfisch on November 02, 2012, 02:13:45 pm
I am using this code for an email form processor:

Code: [Select]
<?PHP
//security function
function IsInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)');
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
     } else {
return false;
     }
}

//Get form entries
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$description = $_POST['job-description'];
$contact_method = $_POST['contact-method'];

//security
if(IsInjected($email)) {
echo "Bad email value!";
exit;
}

//Compose email
$email_from = <valid address>;
$email_subject = "TopPage Design form submission: quotes.html";
$email_body = "*** FORM SUBMISSION *** \n
name: " . $name . "\n
email: " . $email . "\n
phone: " . $phone . "\n
description: " . $description . "\n
contact method: " . $contact_method . "\n
*** END OF EMAIL ***";

//Send email
$to = <valid address>;
$headers = "From" . $email_from . "\r\n";
$headers .= "Reply-To:" . $email . "\r\n";

//send
mail($to, $email_subject, $email_body, $headers);
//success
echo("success.");
?>


But for some reason I don't receive the email, even though i get the success message. Am I doing something wrong?
Title: Re: mail() not working?
Post by: Sorunome on November 02, 2012, 02:23:48 pm
may your mail settings are incorrect in your php.ini, i can't help you much there, sorry
EDIT: just noticed for the headders:
"From: My Secret name <[email protected]>\r\n"
Title: Re: mail() not working?
Post by: flyingfisch on November 02, 2012, 02:32:10 pm
may your mail settings are incorrect in your php.ini, i can't help you much there, sorry
EDIT: just noticed for the headders:
"From: My Secret name <[email protected]>\r\n"

Well, its on juju's server so idk...

also, what do you mean about the headers?
Title: Re: mail() not working?
Post by: Sorunome on November 02, 2012, 02:33:17 pm
you probably need a 57o9.org email then, let juju do the work for you :P
Title: Re: mail() not working?
Post by: flyingfisch on November 02, 2012, 02:33:59 pm
you probably need a 57o9.org email then, let juju do the work for you :P

Oh, it won't work for any address?
Title: Re: mail() not working?
Post by: Eeems on November 02, 2012, 02:45:01 pm
Mail might be disabled in the php.ini. I would ask Juju if he enabled it.
Title: Re: mail() not working?
Post by: Jim Bauwens on November 02, 2012, 02:45:14 pm
It should work without an email account.
You could try if you can send an email using the 'mail' binary.
Title: Re: mail() not working?
Post by: Juju on November 02, 2012, 02:46:33 pm
Yeah, probably a misconfigured php.ini. Might look into this.
Title: Re: mail() not working?
Post by: flyingfisch on November 02, 2012, 02:48:51 pm
Yeah, probably a misconfigured php.ini. Might look into this.

OK, so what should i do in the meantime?
Title: Re: mail() not working?
Post by: Jim Bauwens on November 02, 2012, 02:49:48 pm
You could execute the 'mail' binary from php :P
Title: Re: mail() not working?
Post by: flyingfisch on November 02, 2012, 02:50:53 pm
You could execute the 'mail' binary from php :P

I'm not real knowledgeable with PHP. how would i do that? Thanks. :)
Title: Re: mail() not working?
Post by: Juju on November 02, 2012, 02:58:53 pm
It is now fixed. I think I messed it up when I tried setting up email accounts...

The problem was that I uninstalled sendmail in favor of postfix (they conflict each other), thus breaking everthing.
Title: Re: mail() not working?
Post by: Eeems on November 02, 2012, 03:09:35 pm
How to execute shell commands/binaries
exec() http://www.php.net/manual/en/function.exec.php
shell_exec() http://php.net/manual/en/function.shell-exec.php
system() http://www.php.net/manual/en/function.system.php
passthru() http://www.php.net/manual/en/function.passthru.php
popen() http://www.php.net/manual/en/function.popen.php
pcntl_exec() http://www.php.net/manual/en/function.pcntl-exec.php
I was not aware there was so many x.x Good thing I googled them lol
Title: Re: mail() not working?
Post by: Juju on November 02, 2012, 03:18:19 pm
The mail binary wouldn't work without sendmail properly installed anyway, it is now.
Title: Re: mail() not working?
Post by: flyingfisch on November 02, 2012, 03:24:17 pm
works now, thanks juju :)
Title: Re: mail() not working?
Post by: Jim Bauwens on November 02, 2012, 03:55:36 pm
How to execute shell commands/binaries
exec() http://www.php.net/manual/en/function.exec.php
shell_exec() http://php.net/manual/en/function.shell-exec.php
system() http://www.php.net/manual/en/function.system.php
passthru() http://www.php.net/manual/en/function.passthru.php
popen() http://www.php.net/manual/en/function.popen.php
pcntl_exec() http://www.php.net/manual/en/function.pcntl-exec.php
I was not aware there was so many x.x Good thing I googled them lol

That was the reason why I didn't provide any code for running it :P
It's been too long since I used it.
Title: Re: mail() not working?
Post by: DJ Omnimaga on November 02, 2012, 03:58:12 pm
BY the way is juju server in safe mode? I know on United-TI web hosting I had troubles with mail() due to that (I had a forum installed there and people would never get their activation e-mails and there were other broken stuff as well that are not related to e-mailing, such as automated login)
Title: Re: mail() not working?
Post by: Juju on November 02, 2012, 04:19:46 pm
BY the way is juju server in safe mode? I know on United-TI web hosting I had troubles with mail() due to that (I had a forum installed there and people would never get their activation e-mails and there were other broken stuff as well that are not related to e-mailing, such as automated login)
No. mail() relies on a sendmail binary, which wasn't working.
Title: Re: mail() not working?
Post by: Deep Toaster on November 02, 2012, 06:54:53 pm
It is now fixed. I think I messed it up when I tried setting up email accounts...
Yay!

I noticed mail() doesn't work on your server months ago but I guess I never reported the bug.

I ended up implementing SMTP to send emails through my Gmail address, which made it less spam-block-prone anyway.
Title: Re: mail() not working?
Post by: Sorunome on November 03, 2012, 02:07:53 am
It is now fixed. I think I messed it up when I tried setting up email accounts...
Yay!

I noticed mail() doesn't work on your server months ago but I guess I never reported the bug.

I ended up implementing SMTP to send emails through my Gmail address, which made it less spam-block-prone anyway.
so php mail() is being recognized wildley as spam? that's why my emails always end in the spam folders. How can i overgo that easily? Just buy setting up a SMTP or what?
Title: Re: mail() not working?
Post by: flyingfisch on November 03, 2012, 10:19:16 am
It is now fixed. I think I messed it up when I tried setting up email accounts...
Yay!

I noticed mail() doesn't work on your server months ago but I guess I never reported the bug.

I ended up implementing SMTP to send emails through my Gmail address, which made it less spam-block-prone anyway.

Well, I am only sending emails to myself with the script, and none of the stuff gets in my spam box, so i'm happy. :)
Title: Re: mail() not working?
Post by: Deep Toaster on November 03, 2012, 01:46:34 pm
so php mail() is being recognized wildley as spam? that's why my emails always end in the spam folders. How can i overgo that easily? Just buy setting up a SMTP or what?
No, it's just that Gmail (or whatever email service you use) probably doesn't recognize the server you're sending from. You can use any From address in mail(), so Gmail needs a way to verify you're actually responsible for that mail domain.
Title: Re: mail() not working?
Post by: DJ Omnimaga on November 03, 2012, 01:59:37 pm
Don't Gmail flag stuff as spam only when it contains suspicious content (such as the mispelled words caialias, parno, inlarge) or when multiple identical e-mails are sent from an e-mail address?