Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

PHP contact form problem with email field...

the mail() function

Moderators: macek, egami, gesf

PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 7:46 am

I have a very basic contact form just "Name" and "Email" and using the following way to get the variables but it has a problem just with the email field. I found out when the email address contains "@" it dose not deliver the form.

Code: Select all
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));

I tested to put anything in the email field on my form without the "@" and it works just fine!!

what is wrong please help and I'll appreciate it.
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby Nullsig » Fri Apr 22, 2011 7:57 am

Can you give us the text to the form itself. From the looks of it (other than the fact that trim is all lowercase) The code you displayed should work.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 8:13 am

here it goes the form code:
Code: Select all
<form name="contact" action="test.php" method="post">
<table width="500" border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right"><div align="right">
<p class="CopyrightLine">nome completo:<span class="style1">*</span></p>
</div></td>
<td width="330" align="left"><input name="fullname" type="text" class="SelectingMenu" size="25" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">
<p class="CopyrightLine">email:<span class="style1">*</span></p>
</div></td>
<td><input name="email" type="text" class="SelectingMenu" size="25" maxlength="50"/></td>
</tr>
<tr valign="center">
<td><div align="right">
<p class="CopyrightLine">envie:&nbsp;&nbsp;&nbsp;</p>
</div></td>
<td><div align="left">
<input name="submit" type="submit" value="        submit        " />
</div></td>
</tr>
</table>
</form>


Thanks
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby Nullsig » Fri Apr 22, 2011 9:16 am

can you echo out the e-mail value?

Your code all looks kosher but I think what is happening is the e-mail address is getting URL Encoded so which would corrupt your e-mail

If I am right you should see "someone%40somewhere.com" instead of someone@somewhere.com

if this is the case.... you just need to wrap your string in urldecode() and it should fix it.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 9:33 am

I get all the information echoed out correctly if i don't have the "@" in my "email" box. But as soon as i have the correct email address (which obviusly contains "@") I don't even recive the email at the destination.
I realy don' know what is wrong!?
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby egami » Fri Apr 22, 2011 9:34 am

please post your entire PHP script.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 10:11 am

I don'n have access to it will post it in a few hours for sure...
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby Nullsig » Fri Apr 22, 2011 11:02 am

i mean that you should echo out the e-mail address before you run the email.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 1:37 pm

Here they are the both codes, PHP and HTML:
Code: Select all
<?php
// place the posted data into variables
$EmailFrom = Trim(stripslashes($_POST['email']));
$name = Trim(stripslashes($_POST['fullname']));
$subject = "$EmailFrom";
// prepare email body text
$Body = "";
$Body .= "From: $name";
$Body .= "\n";
$Body .= "Email: $EmailFrom";
$Body .= "\n";
// Enter your email address
$to ='email@domain.com.br';
// From
$header="from: $name <$EmailFrom>";
// send email
$success = mail($to, $subject, $Body, $header);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

and
Code: Select all
<form name="contact" action="test.php" method="post">
<table width="500" border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right"><div align="right">
<p class="CopyrightLine">nome completo:<span class="style1">*</span></p>
</div></td>
<td width="330" align="left"><input name="fullname" type="text" class="SelectingMenu" size="25" maxlength="30" /></td>
</tr>
<tr>
<td><div align="right">
<p class="CopyrightLine">email:<span class="style1">*</span></p>
</div></td>
<td><input name="email" type="text" class="SelectingMenu" size="25" maxlength="50"/></td>
</tr>
<tr valign="center">
<td><div align="right">
<p class="CopyrightLine">envie:&nbsp;&nbsp;&nbsp;</p>
</div></td>
<td><div align="left">
<input name="submit" type="submit" value="        submit        " />
</div></td>
</tr>
</table>
</form>
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 2:29 pm

I just found out that in fact the form does not accept any email address such as "email@domain.com", the problem is not with the "@".

For instance accepts "email@domaincom" or "emaildomain.com" but as soon as type in the email in the correct manner (email@domain.com) the form goes to OK page but I don't receive the email!
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby Brasil360 » Fri Apr 22, 2011 5:35 pm

I haven't find out the answer yet but this bit of the PHP code is causing the problem:
Code: Select all
// From
$header="from: $name <$EmailFrom>";


Which results in this problem that when i receive the email appears a domain name at the end of the email address:
Code: Select all
From:"name" <name@emailcom.whservidor.com>


How should I change the line in the PHP code to get read of this domain extention?
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby Brasil360 » Sun Apr 24, 2011 3:06 am

Well thanks everyone here trying to help. I called my host company and they explained that all these are happening because I must be using SMTP authentication code and bunch of other things which now they provided me with. It looks everything works just fine. :)
Brasil360
New php-forum User
New php-forum User
 
Posts: 12
Joined: Fri Apr 22, 2011 6:46 am
Location: BH, MG, Brazil

Re: PHP contact form problem with email field...

Postby andyrichin » Mon May 02, 2011 7:01 am

@Brasil360 I have been having the same issue. What did you have to do to get it to work? Would you be able to provide me with your HTML and PHP scripts? Would be awesome! Thanks.
andyrichin
New php-forum User
New php-forum User
 
Posts: 22
Joined: Fri Apr 29, 2011 5:02 pm

Re: PHP contact form problem with email field...

Postby lovewow » Sat May 21, 2011 1:18 am

if this is the case.... you just need to wrap your string in urldecode() and it should fix it.

I like fashion life and go to buy burberry bags and Cheap Marc Jacobs Handbags, thecheap burberry bags is ok.
lovewow
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat May 21, 2011 1:01 am

Re: PHP contact form problem with email field...

Postby webinfopedia » Sat May 21, 2011 10:39 pm

Below i will explain you how to make a email form
Code: Select all
<form method="post" action="phpmail.php">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td colspan="3" align="left" valign="middle" bgcolor="#008000"><div style="margin:0px 10px; font-weight:bold; color:#FFF; font-size:16px;">PHP email function</div></td>
    </tr>
  <tr>
    <td width="13%" align="left" valign="middle"><strong>Name</strong></td>
    <td width="2%" align="left" valign="middle">:</td>
    <td width="85%" align="left" valign="middle"><label>
      <input name="name" type="text" class="textbox" id="name" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Email</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="email" type="text" class="textbox" id="email" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Mobile No</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <input name="mobile" type="text" class="textbox" id="mobile" />
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle"><strong>Message</strong></td>
    <td align="left" valign="middle">:</td>
    <td align="left" valign="middle"><label>
      <textarea name="message" rows="3" class="textbox" id="message"></textarea>
    </label></td>
  </tr>
  <tr>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle">&nbsp;</td>
    <td align="left" valign="middle"><label>
      <input name="button" type="submit" class="submit" id="button" value="Send Email" />
    </label></td>
  </tr>
</table>
</form>

Now to this HTML form we have to write the PHP script.Find it below
Code: Select all
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$message=$_POST['message'];

$to=$email;
$subject="Welcome to www.webinfopedia.com";

$message="From:$name <br />Mobile:$mobile <br />".$message;

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

// More headers
$headers .= 'From: <name@yourwebsite.com>' . "\r\n";
$headers .= 'Cc: name@yourwebsite.com' . "\r\n";
@mail($to,$subject,$message,$headers);
if(@mail)
{
echo "Email sent successfully !!";   
}
?>

If you want learn more about PHP visit http://www.webinfopedia.com
User avatar
webinfopedia
New php-forum User
New php-forum User
 
Posts: 84
Joined: Sat May 21, 2011 10:26 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron