1

I've been struggling with this the entire day. The server used to work without smtp authentication. Now it doesn't anymore. So I created a mail adress to forward the filled in scripts to my email adress. I used to get errors. Now I'm not getting any errors anymore, but I'm still not getting the any mail.

Maybe you guys can see if there is something wrong with my code.

require_once "Mail.php";
$recipient = "mwmhermans@outlook.com"; //Het email adres van de persoon die vragen moet ontvangen. 
$subject = "Dealership request." + $_POST['naam']; //Subject van de mail. 
$header = "From: " . $_POST['email'] . "\n"; 
$mail_body = "Contact script was executed on " . date("d-m-Y") . " at " . date("H:i") . " \n";  // tijd van uitvoering
$mail_body .= "The following person executed the script:\n\n";
$mail_body .= "Name: " . $_POST['naam'] . "\n"; 
$mail_body .= "E-mail: " . $_POST['email'] . "\n\n";
$mail_body .= "Company: " . $_POST['company'] . "\n"; 

$host = "";
$username = "";
$password="";

$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($recipient, $subject, $header, $body);

echo '<div style="margin-left:25px;"><div class="wrapper">';
echo "<br/><b>Your request is successfully sent.</b><br>You'll get a response as soon as possible.</b><br>"; 
echo "<a class=\"main\" href='javascript:history.back(1)'>Back</a>";
echo '</div></div>'; 
Charles
  • 50,943
  • 13
  • 104
  • 142
  • 1
    What's in the logs? does your class return any errors? How is this class, which you use, is named (name of the library)? – JimiDini Sep 30 '13 at 16:38
  • Have you checked spam folders? – Justin Wood Sep 30 '13 at 16:38
  • I do believe headers need to be the last entry. Try `$mail = $smtp->send($recipient, $subject, $body, $header);` – Funk Forty Niner Sep 30 '13 at 16:40
  • I checked the logs no errors at all –  Sep 30 '13 at 16:43
  • doesnt show up in spam folders. @Fred-ii- tried it didn't work unfortunatly –  Sep 30 '13 at 16:45
  • @TheUnknown This line doesn't seem right with the `+` sign `$subject = "Dealership request." + $_POST['naam'];` I think what you're trying to do is concatenate the subject with the person's name. Try `$subject = "Dealership request" . $_POST['naam'];` or `$subject = "Dealership request" . $_POST['naam'] . "\r\n";` – Funk Forty Niner Sep 30 '13 at 16:46
  • 1
    `if (PEAR::isError($mail)) { echo $mail->getMessage(); }` – Samuel Cook Sep 30 '13 at 16:53
  • tried changing that too no still no email though. –  Sep 30 '13 at 16:54
  • @SamuelCook thanks now I know that i need to make the header a array –  Sep 30 '13 at 17:32

1 Answers1

1

I think, you are setting incorrect parameters to send function. As manual page says, the synopsis is:

mixed send ( mixed $recipients , array $headers , string $body )

While you are calling it like this:

send(mixed $recipient, string $subject, string $header, string $body);

Please, look at the example on that page and change your code according to it.

user4035
  • 22,508
  • 11
  • 59
  • 94
  • atleast it is sending me a mail now. but its sending me a failure notice –  Sep 30 '13 at 17:46
  • @TheUnknown Please, explain, what a failure notice is, how it is generated? Try to debug yourself too. – user4035 Sep 30 '13 at 17:47
  • I used the debug again nothing comes up, it seems to be a server problem this is what i get in my mailbox http://skyhighcaraudio.net/Knipsel.PNG –  Sep 30 '13 at 17:57
  • figured out that I messed up on the From –  Sep 30 '13 at 18:10
  • @TheUnknown Great. Glad, that you did it. – user4035 Sep 30 '13 at 19:19
  • Today I tried to change the php version to php 5.4 since it was still at 5.2 but after I did that the mail function didn't work anymore. Any idea how this could be. –  Oct 03 '13 at 19:43
  • @TheUnknown Did you put the headers into array and did everything according to manual? Any errors? – user4035 Oct 03 '13 at 20:12
  • just was about to come back and say that I found a error after debugging. I made a typo and apperantly that wasn't a problem in 5.2 but it was in 5.4 –  Oct 03 '13 at 20:27