PHP Mail Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nlimpag07
Forum Newbie
Posts: 10
Joined: Wed Jun 23, 2010 9:39 pm

PHP Mail Problem

Post by nlimpag07 »

Hi!! i am stuck in this problem... i almost viewed the whole google... :P. but still cant get my code functionable...

i i want to send email using php. Try to look ..

Code: Select all

<?
//Check whether the submission is made
if(isset($Send)){
$username = 'username';
     $txtSub = 'sub';
$lastname = 'Lname';
$phone = 'number';
$txtEmailfrm = 'Umail';
$msg = 'msg';
$email_To= "noellimpag@yahoo.com";

$txtMsg =
 "Someone Sends you an email.../n
 
 Mailer Name:    $username $lastname /n
 Mailer Address: $add /n
 Mailer Number:  $phone /n/n
 $msg

"
//Declarate the necessary variables
$mail_to=$email_To;
$mail_from=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;


//Check for success/failure of delivery
mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")
?>


 <form method="post" action="" onSubmit="return ValidationForm()">
                      <div class="formtitle">Your Name*:</div><div class="formentry"><input name="username" type="text"class="formcolor" ></div>
                      <div class="formtitle">Last Name*:</div><div class="formentry"><input name="Lname" type="text"class="formcolor"></div>
                      <div class="formtitle"></div>
                      <div class="formentry"></div>
                      <div class="formtitle">Your E-mail*:</div><div class="formentry"><input name="Umail" type="text"class="formcolor"></div>
                      <div class="formtitle">Phone Number*:</div><div class="formentry"><input name="number" type="text"class="formcolor"></div>
                      <div class="formtitle">Subject*:</div><div class="formentry"><input name="sub" type="text"class="formcolor"></div>
                           
                      <div class="msglabel"><div class="formtitle">Message:</div></div><div class="msgsize"><textarea name="msg" cols="30" rows="6" class="formcolor">asdasdasdasd</textarea></div>
                       <div class="reg"><input name="Send" type="submit" id="Send" value="Send"class="formcolor" ></div>
                   </form>


Pls.. Anyone can help me make this code functionable?

Replies Really needed..
Last edited by Benjamin on Fri Jun 25, 2010 2:54 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Mail Problem

Post by requinix »

nlimpag07 wrote:Anyone can help me make this code functionable?
Depends. How is it not "functionable" right now?
User avatar
nlimpag07
Forum Newbie
Posts: 10
Joined: Wed Jun 23, 2010 9:39 pm

Re: PHP Mail Problem

Post by nlimpag07 »

Thanks for editing... and sorry i don't use the php syntax..
Yup its not functionable(may not the right word). I had uploaded it on my server and try it but it didn't send an email...
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: PHP Mail Problem

Post by rahulzatakia »

Hi, there was many syntax errors in your code so i have corrected them. Check out the following code. Still if you have any problem let us know.

Code: Select all



<?
//Check whether the submission is made
if(isset($_POST['Send'])){

$username = $_POST['username'];
     $txtSub = $_POST['sub'];
$lastname = $_POST['Lname'];
$phone = $_POST['number'];
$txtEmailfrm = $_POST['Umail'];
$msg = $_POST['msg'];
$email_To= "noellimpag@yahoo.com";

$txtMsg =
 "Someone Sends you an email.../n
 
 Mailer Name:    $username $lastname /n
 Mailer Number:  $phone /n/n
 $msg";
//Declarate the necessary variables
$mail_to=$email_To;
$mail_from=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;


//Check for success/failure of delivery
mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from");
}
?>


 <form method="post" action="" onSubmit="return ValidationForm()">
                      <div class="formtitle">Your Name*:</div><div class="formentry"><input name="username" type="text"class="formcolor" ></div>
                      <div class="formtitle">Last Name*:</div><div class="formentry"><input name="Lname" type="text"class="formcolor"></div>
                      <div class="formtitle"></div>
                      <div class="formentry"></div>
                      <div class="formtitle">Your E-mail*:</div><div class="formentry"><input name="Umail" type="text"class="formcolor"></div>
                      <div class="formtitle">Phone Number*:</div><div class="formentry"><input name="number" type="text"class="formcolor"></div>
                      <div class="formtitle">Subject*:</div><div class="formentry"><input name="sub" type="text"class="formcolor"></div>
                           
                      <div class="msglabel"><div class="formtitle">Message:</div></div><div class="msgsize"><textarea name="msg" cols="30" rows="6" class="formcolor">asdasdasdasd</textarea></div>
                       <div class="reg"><input name="Send" type="submit" id="Send" value="Send"class="formcolor" ></div>
                   </form>

Last edited by rahulzatakia on Fri Jun 25, 2010 5:23 am, edited 1 time in total.
amitdubey2
Forum Commoner
Posts: 48
Joined: Tue Apr 13, 2010 10:13 pm

Re: PHP Mail Problem

Post by amitdubey2 »

hi,
just said..there are many syntax error..in your code..
You may use the following code..it is not doing the validation part ..but let me know if you want validation.
here is the code..

Code: Select all

<?php
//Check whether the submission is made
if(isset($_POST['submit'])){
$username = $_POST['username'];
     $txtSub = $_POST['sub'];
$lastname = $_POST['Lname'];
$phone = $_POST['number'];
$txtEmailfrm = $_POST['Umail'];
$msg = $_POST['msg'];
$email_To= "noellimpag@yahoo.com";

$txtMsg ="Someone Sends you an email...\n Mailer Name:$username $lastname \n Mailer Number:  $phone \n message: $msg \n";
//Declarate the necessary variables
$mail_to=$email_To;
$email=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;
$headers = "From: $email\r\n" ."X-Mailer: php";

//Check for success/failure of delivery
if(mail($mail_to,$mail_sub,$mail_mesg,$headers))
{
echo"message sent";
}
else
{
echo"Not sent";
}
}
?>


 <form method="post" action="">
                      <div class="formtitle">Your Name*:</div><div class="formentry"><input name="username" type="text"class="formcolor" ></div>
                      <div class="formtitle">Last Name*:</div><div class="formentry"><input name="Lname" type="text"class="formcolor"></div>
                      <div class="formtitle"></div>
                      <div class="formentry"></div>
                      <div class="formtitle">Your E-mail*:</div><div class="formentry"><input name="Umail" type="text"class="formcolor"></div>
                      <div class="formtitle">Phone Number*:</div><div class="formentry"><input name="number" type="text"class="formcolor"></div>
                      <div class="formtitle">Subject*:</div><div class="formentry"><input name="sub" type="text"class="formcolor"></div>
                           
                      <div class="msglabel"><div class="formtitle">Message:</div></div><div class="msgsize"><textarea name="msg" cols="30" rows="6" class="formcolor">asdasdasdasd</textarea></div>
                       <div class="reg"><input name="submit" type="submit" id="Send" value="submit"class="formcolor" ></div>
                   </form>



cheers..
amit :drunk:
User avatar
nlimpag07
Forum Newbie
Posts: 10
Joined: Wed Jun 23, 2010 9:39 pm

Re: PHP Mail Problem

Post by nlimpag07 »

Thanks a lot guys and also to you amit... can i ask for the validation amit?.. if u don't mind... thanks in advance..
amitdubey2
Forum Commoner
Posts: 48
Joined: Tue Apr 13, 2010 10:13 pm

Re: PHP Mail Problem

Post by amitdubey2 »

hi nlimpag07,

This is the code with validation .. it will work for you. :D :)

Code: Select all

<SCRIPT SRC="translate.js"></SCRIPT>
<SCRIPT LANGUAGE="javascript"> 
function checkfield(loginform)
{
	ok=true
	if(loginform.username.value=="")
	{
		alert("Please Enter Your First Name.")
		loginform.username.focus()
		ok=false
	}
	else if(loginform.Lname.value=="")
	{
		alert("Please Enter Your Last Name.")
		loginform.Lname.focus()
		ok=false
	}
	else if(loginform.number.value=="")
	{
		alert("Please Enter your contact Number.")
		loginform.number.focus()
		ok=false
	}
	else if(loginform.subject.value=="")
	{
		alert("Please Enter the subject.")
		loginform.subject.focus()
		ok=false
	}
	else if (loginform.msg.value == "")
	{
		alert("Please leave some message.");
		loginform.msg.focus();
		ok=false
	}

	else if (loginform.email.value == "")
	{
		alert("Please enter a value for the email field.");
		loginform.email.focus();
		ok=false
	}
	else if (!isEmailAddr(loginform.email.value))
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		loginform.email.focus();
		ok=false
	}
	return ok
}
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
	var pindex = theStr.indexOf(".",index);
	if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
</SCRIPT>



<?php
//Check whether the submission is made
if(isset($_POST['submit'])){
$username = $_POST['username'];
     $txtSub = $_POST['subject'];
$lastname = $_POST['Lname'];
$phone = $_POST['number'];
$txtEmailfrm = $_POST['email'];
$msg = $_POST['msg'];
$email_To= "noellimpag@yahoo.com";

$txtMsg ="Someone Sends you an email...\n Mailer Name:$username $lastname \n Mailer Number:  $phone \n message: $msg \n";
//Declarate the necessary variables
$mail_to=$email_To;
$email=$txtEmailfrm;
$mail_sub=$txtSub;
$mail_mesg=$txtMsg;
$headers = "From: $email\r\n" ."X-Mailer: php";

//Check for success/failure of delivery
if(mail($mail_to,$mail_sub,$mail_mesg,$headers))
{
echo"message sent";
}
else
{
echo"Not sent";
}
}
?>


 <form name="loginform" method="post" action="" ONSUBMIT="return checkfield(loginform)">
 <INPUT NAME="required" TYPE="hidden" VALUE="uname,Lname,email,subject,number,msg">
 <INPUT NAME="sort" TYPE="hidden" VALUE="uname,Lname,email,subject,number,msg">                  
 <div class="formtitle">Your Name*:</div><div class="formentry"><input name="username" type="text"class="formcolor" ></div>
                      <div class="formtitle">Last Name*:</div><div class="formentry"><input name="Lname" type="text"class="formcolor"></div>
                      <div class="formtitle"></div>
                      <div class="formentry"></div>
                      <div class="formtitle">Your E-mail*:</div><div class="formentry"><input name="email" type="text"class="formcolor"></div>
                      <div class="formtitle">Phone Number*:</div><div class="formentry"><input name="number" type="text"class="formcolor"></div>
                      <div class="formtitle">Subject*:</div><div class="formentry"><input name="subject" type="text"class="formcolor"></div>
                           
                      <div class="msglabel"><div class="formtitle">Message:</div></div><div class="msgsize"><textarea name="msg" cols="30" rows="6" class="formcolor"></textarea></div>
                       <div class="reg"><input name="submit" type="submit" id="Send" value="submit"class="formcolor" ></div>
                   </form>

Feel free to contact if you have problem in this.


Cheers :drunk:
amit
User avatar
nlimpag07
Forum Newbie
Posts: 10
Joined: Wed Jun 23, 2010 9:39 pm

Re: PHP Mail Problem

Post by nlimpag07 »

Thanks amit... thank you very much...
Post Reply