You are not logged in.

#1 2010-02-06 00:27:54

jumzi
Member
Registered: 2009-02-20
Posts: 69

[SOLVED]PHP mail() problems

Heja! Got some PHP problems:

Trying to use the php mail function and in my test i wrote one html file that forwards variables via POST. The problem is that the mail function doesn't work when i'm using POST variables, only static variables. Also $mailsuccess doesn't put something out when i try and echo it, but i can use it in the if...else statement (if i compare with FALSE it will echo "Mail is succefully sent"). Is there some reason to this or am i doing something wrong? (Still kinda new to PHP)

<html>
<head>
</head>
<body>
<p>Mail Testing</p>
</br>
<form action="mailsender.php" method="post">
  <table>
    <tr>
      <td>Mail Adress</td>
      <td><input type="text" name="adress" /></td>
    </tr>
    <tr>
      <td>Subject</td>
      <td><input type="text" name="subject" /></td>
    </tr>
    <tr>
      <td>Message</td>
    </tr>
    <tr>
      <td>
      </td>
      <td><textarea name="message" rows="15" cols="40"/>put text here!</textarea></td>
    </tr>
    <tr>
    <td colspan="2" style="text-align: center;">
      <input type="submit" name="submit" value="Send Message" /></td>
    </td> 
  </table>
</form>
</body>
</head>
</html>
<?php
$mailsuccess = mail($_POST['adress'],$_POST['subject'],$_POST['message']);
echo $mailsuccess;
if($mailsuccess == TRUE)
  echo "<p>Mail is successfully sent</p>";
else
  echo "<p>Unable to send the message</p>";
echo '<p>lala' . $mailsuccess . '</p>';

#mail('somemail@someprovider.something','lala','saoeulala');
print_r($_POST);
echo '<p>This is some text</p>';
?>

Last edited by jumzi (2010-02-07 01:15:35)

Offline

#2 2010-02-06 04:21:55

n0dix
Member
Registered: 2009-09-22
Posts: 956

Re: [SOLVED]PHP mail() problems

Do you read the documentation? http://php.net/manual/en/function.mail.php.
You need to specified the from/to emails.

If you compared to FALSE works because, the mail function isn't working well.

Last edited by n0dix (2010-02-06 04:24:00)

Offline

#3 2010-02-06 07:45:49

jumzi
Member
Registered: 2009-02-20
Posts: 69

Re: [SOLVED]PHP mail() problems

It's actually not needed i can get it working with static variables without the "from" in the optional addtional header. Altough it stands you must have it... The problem still seemes to be the POST variables that for some reason aint working. and "mail function isn't working well" is an intressting diagnosis... Well i spose i could sleep on it and try again tomorrow wink

Offline

#4 2010-02-06 08:00:26

Andrwe
Member
From: Leipzig/Germany
Registered: 2009-06-17
Posts: 322
Website

Re: [SOLVED]PHP mail() problems

Please check the content of $_POST using var_dump($_POST) somewhere in the php-code and try var_dump($mailsuccess) to check its content.


Website: andrwe.org

Offline

#5 2010-02-07 00:58:35

jumzi
Member
Registered: 2009-02-20
Posts: 69

Re: [SOLVED]PHP mail() problems

Yeah well i have now woken up and eaten lots of food and solved the problem big_smile

Essentially the php mail() function works with sendmail (or msmtp as i do) and my apache server is automatically running as the http user. This user however didn't have the permission to even use msmtp, wich is confusing since "others" are allowed to execute the bin file. Anyway switching the user in the apache conf worked but now i'm abit confused in what permissions i have to give the http user.

Anyway this problem is atleast solved, altough it spawned some more.

Offline

Board footer

Powered by FluxBB