Jump to content

PHP mail sending form not arriving in "all" mailboxes. SMTP problem ?


Duofilm

Recommended Posts

As my titel indicates, I have a problem with a piece of code I wrote some time ago.

Everything in my mail form is fine and the mails do get send. But they don't always arrive (checked spam folder).

Hotmail or example arrives but a normal email adres from a provider does not.

Could this have something to do with SMTP ? could I add this to my code ?

I tryed some but so far it does not work, In the code below you can see my working code as it is & the tests I tryed and didn't work out that well.

 

 

<?php $fromemail="No-Reply <ikwerkthuis.be>"; // change here if you want
$toemail=$naarwie;   // change here if you want
$sub="Online info aanvraag";          // change here if you want
$success_page_name="bedankt.html";
////// do not change in following
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1']));  
$fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2']));  
$fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3']));  
$fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4']));  
$fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5']));  
$fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6']));  
$fieldnm_7=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_7'])); 


$contentmsg=stripslashes('<br><b><font style=color:#CC3300>'. $sub .'</font></b><br>
<table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_1 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_2 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_3 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_4 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_5 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_6 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Regio *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_7 .'</td>
</tr>

</table><br>
Contactpersoon: '. $naarwie .'<br>
IP: '. $IP .'<br>
Date: '. $DATE .'<br>
Time: '. $TIME .'
');

////
$headers  = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";

$from=$fromemail;

$headers .= "From: ".$from." 
";

@mail($toemail,$sub,$contentmsg,$headers);?>

 

The code below is the code I tryed to apply to the code above that work.

 

<?php $fromemail="No-Reply <noreply@ikwerkthuis.be>"; // change here if you want
$toemail=$naarwie;   // change here if you want
$sub="Online info aanvraag";          // change here if you want
$success_page_name="bedankt.html";
$host = "ikwerkthuis.be";
$username = "noreply@ikwerkthuis.be";
$password = "hl2012";
////// do not change in following
if($_SERVER['REQUEST_METHOD']=="POST")
{
$fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1']));  
$fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2']));  
$fieldnm_3=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_3']));  
$fieldnm_4=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_4']));  
$fieldnm_5=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_5']));  
$fieldnm_6=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_6']));  
$fieldnm_7=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_7'])); 


$contentmsg=stripslashes('<br><b><font style=color:#CC3300>'. $sub .'</font></b><br>
<table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Voornaam *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_1 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Achternaam *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_2 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>E-mail *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_3 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Telefoon *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_4 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Werkstatus *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_5 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Leeftijd *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_6 .'</td>
</tr>

<tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Regio *:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>'. $fieldnm_7 .'</td>
</tr>

</table><br>
Contactpersoon: '. $naarwie .'<br>
IP: '. $IP .'<br>
Date: '. $DATE .'<br>
Time: '. $TIME .'
');

////
$headers  = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";

$from=$fromemail;

$headers .= "From: ".$from." 
";
$smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));


@mail = $smtp->send($toemail,$sub,$contentmsg,$headers); ?>

 

I hope someone can help me out.

Thanks in advance !

Link to comment
Share on other sites

you can't just drop smtp details into the mail script, you need to set them in your ini files and even then that will only work on Linux servers.  Your issue is most likely that you are not building full headers.  A lot of ISP's will just dump mail without even thinking if the headers are malformed or incomplete, it won't flag the message as spam, it will just delete it from the server and that's the end of it.

 

If it was an smtp issue you wouldn't be getting any of the mails out (trust me).  SMTP is the outbound part of the process, not the inbound part. 

 

Look up how to build headers that are complete and accurate, this should fix your issue.

Link to comment
Share on other sites

I looked it up made some minor changes... Since there wasn't much to change according to what I found on the internet.

 

<?php $fromemail="No-Reply <ikwerkthuis.be>"; // change here if you want
$toemail=$naarwie;   // change here if you want
$sub="Online info aanvraag";          // change here if you want
$contentmsg="blabla"
$success_page_name="bedankt.html";

$headers  = "From:".$fromemail."";
$headers .= "MIME-Version: 1.0";
$headers .= "Content-type: text/html; charset=iso-8859-1";			

@mail($toemail,$sub,$contentmsg,$headers); ?>

 

Its still doesn't send to all emails some work some don't.. any other ideas ? or anything wrong with my headers here ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.