PDA

View Full Version : PHP Mail help needed plz



Bonezmann
08-09-2009, 09:47 PM
Hi there, I seem to be having some trouble sending mail via PHP. Here's my mail code in a PHP script called contact.php


<?php
$to = "email@email.com";
$subject = "Contact Us";
$Fname = $_REQUEST['Fname'] ;
$Lname = $_REQUEST['Lname'] ;
$message = $_REQUEST['message'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>


Now I fill in the form(registration.php) and then the info I want gets sent here(apparently). Now my problem is that although it states that the email has been sent, it never reaches my inbox. I have checked in all my spam folders.

Help plz? ;_;

Necrolis
09-09-2009, 12:59 PM
testing this out on my xampp setup, it works great(though i don't have $email defined so its "unknown sender"), but it wouldn't send the mail till I propelry configured the DNS server for my SMTP mail client(i'm using mercury/32, which i've never needed before, which is why i was missing configs), so its probably your SMTP settings thats broken

Bonezmann
09-09-2009, 01:19 PM
It isn't on my own server, it's on an external server. godaddy to be precise. I'll see if there are any smtp settigs I can configure. Thanx :)

Banlam
11-09-2009, 11:43 AM
Your smtp server should be that corresponding to your hosting service.
I have some hosting with serv.co.za and their smtp server is mail.<mydomain>.co.za.
In the settings they sent you to setup the hosting (login details etc), they should have sent you details to send and receive e-mails, the smtp server should be listed there.
I know using a Joomla setup there is an option in the settings to set the smtp server.

Bonezmann
14-09-2009, 06:54 PM
Thanx for all the help guys, now I have a new problem. The mail is sent, but it appears blank. There's no info in there. I suspect it might be the 'communication' between contact.php(above script) and the form file.

I've checked the variable names, and they correspond. Can I merge the two files so I only use one file? and if so could you help me or point me in the direction of some tutorials?

Chippit
14-09-2009, 08:20 PM
Post your <form> tag and its contents here. There might be something wrong there that you're not seeing.

As for merging the content into a single script, you can do that by simply checking if all your POST/GET variables are valid right at the start of the script, and then either sending the email or outputting the forum depending on whether you have values or not. You can use this same technique to make validating those inputs easy too.

Bonezmann
14-09-2009, 08:28 PM
<?php
$Fname = $_POST [ "First Name" ];
$Lname = $_POST [ "Last Name" ];
$paddress = $_POST [ "Postal Address" ];
$telwork = $_POST [ "Work Contact number" ];
$telhome = $_POST [ "Home Contact number" ];
$telcell = $_POST [ "Cellphone Contact number" ];
$email = $_POST [ "E-mail Adress" ];
$nationality = $_POST [ "Nationality" ];
$datebirth = $_POST [ "Date Of Birth" ];
$placebirth = $_POST [ "Place Of Birth" ];
$idpass = $_POST [ "I.D or Passport number" ];
$sexuality = $_POST [ "Sexuality" ];
$fathernames = $_POST [ "Father's Full Names" ];
$mothersnames = $_POST [ "Mother's Full Names" ];
$parentspost = $_POST [ "Parent's Postal Address" ];
$maritial = $_POST [ "Maritial Status" ];
$numberchildren = $_POST [ "Number of Children" ];
$childrensage = $_POST [ "Age of Children" ];
$chruchhome = $_POST [ "Your Church Home" ];
$howlongchurch = $_POST [ "How long have you been at this Church" ];
$pastorname = $_POST [ "Your Pastor's name" ];
$pastoraddress = $_POST [ "Your Pastor's address" ];
$churchact = $_POST [ "Church activities you are part of" ];
$primschool = $_POST [ "Primary School" ];
$primgrade = $_POST [ "Primary School Grade" ];
$highschool = $_POST [ "High School" ];
$highgrade = $_POST [ "High School Grade" ];
$coltech = $_POST [ "College/Technical" ];
$coltechqual = $_POST [ "College/Technical Qualifications" ];
$univer = $_POST [ "University"];
$Uniqual = $_POST [ "University Qualifications" ];
$health = $_POST [ "Health Status" ];
$whenchris = $_POST [ "When did you become a Christian" ];
$baptized = $_POST [ "Are you Baptized" ];
$baptizedwhen = $_POST [ "If Yes, when were you Baptized" ];
$holybap = $_POST [ "Have you been BAptized by the Holy Spirit" ];
$holybapwhen = $_POST [ "When were you Baptized by the Holy Spirit" ];
$mincallhow = $_POST [ "How do you know that you are called to the Ministry" ];
$minigifts = $_POST [ "What Ministry Gifts do you have" ];
$whyhibtc = $_POST [ "Why do you intend to study at HIBTC" ];
$accrules = $_POST [ "If accepted, will you obey the rules and regulations of HIBTC" ];
$testimony = $_POST [ "Your short testimony of how you became a Christian" ];
$message = ("Hi there $Name");
?>


<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="contact.php">
<p>First Name :
<input type="text" size="12" maxlength="12" name="Fname">
</p>
<p><br />
Last Name :
<input type="text" size="12" maxlength="36" name="Lname">
</p>
<p>Enter your Postal Address: <br />
<textarea name="paddress" cols="20" rows="5" wrap="physical" id="paddress">Enter your Postal Address</textarea>
</p>
<p> <br />

Contact Numbers:
<p>Work :
<input name="telwork" type="text" id="telwork" size="20" maxlength="12">
</p>
<p>
Home :
<input name="telhome" type="text" id="telhome" size="20" maxlength="36">
</p>
<p>Cell :
<input name="telcell" type="text" id="telcell" size="20" maxlength="36">
</p>
<p>Email address:
<input name="email" type="text" id="email" size="20" maxlength="36">
</p>
<p>Nationality:
<input name="nationality" type="text" id="nationality" size="12" maxlength="36">
</p>
<p>Date of Birth:
<input name="datebirth" type="text" id="datebirth" size="12" maxlength="36">
</p>
<p>Place of Birth:
<input name="placebirth" type="text" id="placebirth" value="" size="30" maxlength="5">
</p>
<p>I.D/Passport number:
<input name="idpass" type="text" id="idpass" size="30" maxlength="36">
</p>
<p>Sexuality:
<select name="sexuality" size="1" id="sexuality">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p>Full names of Father:
<input name="fathernames" type="text" id="fathernames" size="35" maxlength="50">
</p>
<p>Full names of Mother
<input name="mothernames" type="text" id="mothernames" size="35" maxlength="50">
</p>
<p>Parents' Postal address:<br>
<textarea name="parentspost" cols="20" rows="5" id="parentspost"></textarea>
</p>
<p>Maritial status:
<select name="maritial" size="1" id="maritial">
<option value="single" selected>Single</option>
<option value="engaged">Engaged</option>
<option value="married">Married</option>
<option value="seperated">Seperated</option>
<option value="divorced">Divorced</option>
</select>
</p>
<p>If Married, how many children:
<input name="numberchildren" type="text" id="numberchildren" size="12" maxlength="36">
, ages
<input name="childrensage" type="text" id="childrensage" size="12" maxlength="36">
</p>
<p>Your Church Home:<br>
<textarea name="chruchhome" cols="30" rows="5" id="chruchhome"></textarea>
</p>
<p>How long have you been at this church:
<input name="howlongchurch" type="text" id="howlongchurch" size="20" maxlength="36">
</p>
<p>Name of your Pastor:
<input name="pastorname" type="text" id="pastorname" size="30" maxlength="36">
</p>
<p>Address of your Pastor:<br>
<textarea name="pastoraddress" cols="25" rows="5" id="pastoraddress"></textarea>
</p>
<p>What church activities are you currently involved in:<br>
<textarea name="churchact" cols="30" rows="10" id="churchact"></textarea>
</p>
<p>Educational background:</p>
<p>Primary School:
<input name="primschool" type="text" id="primschool" size="30" maxlength="36">
Grade:
<select name="primgrade" size="1" id="primgrade">
<option value="grade 1">Grade 1</option>
<option value="grade 2">Grade 2</option>
<option value="grade 3">Grade 3</option>
<option value="grade 4" selected>Grade 4</option>
<option value="grade 5">Grade 5</option>
<option value="grade 6">Grade 6</option>
<option value="grade 7">Grade 7</option>
</select>
</p>
<p>High School:
<input name="highschool" type="text" id="highschool" size="30" maxlength="36">
Grade:
<select name="highgrade" size="1" id="highgrade">
<option value="grade 8">Grade 8</option>
<option value="grade 9">Grade 9</option>
<option value="grade 10">Grade 10</option>
<option value="grade 11">Grade 11</option>
<option value="grade 12">Grade 12</option>
</select>
</p>
<p>College/ Technical:
<input name="coltech" type="text" id="coltech" size="25" maxlength="36">
</p>
<p>College/Technical Qualifications:<br>
<textarea name="coltechqual" cols="30" rows="10" id="coltechqual"></textarea>
</p>
<p>University:
<input name="univer" type="text" id="univer" size="30" maxlength="36">
</p>
<p>University Qualifications:<br>
<textarea name="Uniqual" cols="30" rows="10" id="Uniqual"></textarea>
</p>
<p>Health Status:
<select name="health" size="1" id="health">
<option value="excellent">Excellent</option>
<option value="very good">Very Good</option>
<option value="good">Good</option>
<option value="poor">Poor</option>
</select>
</p>
<p>When did you become a Christian:
<input name="whenchris" type="text" id="whenchris" size="20" maxlength="36">
</p>
<p>Are you Baptized:
<select name="baptized" size="1" id="baptized">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
If Yes, when:
<input name="baptizedwhen" type="text" id="baptizedwhen" size="12" maxlength="36">
</p>
<p>Have you been Baptized by the Holy Spirit
<select name="holybap" size="1" id="holybap">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
, and when
<input name="holybapwhen" type="text" id="holybapwhen" size="12" maxlength="36">
</p>
<p>How do you know that you are called to the Ministry:<br>
<textarea name="mincallhow" cols="50" rows="20" id="mincallhow"></textarea>
</p>
<p>What Ministry Gifts do You have: <br>
<textarea name="minigifts" cols="30" rows="10" id="minigifts"></textarea>
</p>
<p>Why do you intend to study at HIBTC:<br>
<textarea name="whyhibtc" cols="30" rows="10" id="whyhibtc"></textarea>
</p>
<p>If accepted, are you going to obey HIBTC rules and regulations:
<select name="accrules" size="1" id="accrules">
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</p>
<p>Write a short Testimony of how you became a Christian:<br>
<textarea name="testimony" cols="50" rows="30" id="testimony"></textarea>
</p>
<p>Date:
<input name="date" type="text" id="date" size="12" maxlength="36">
<br>
<br>
<input name="Reset" type="reset" id="Reset" value="Reset">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>

There's the whole script, I can't seem to find the form tag. I got some tips from this (http://www.tizag.com/phpT/examples/formfinale.php) tutorial and used it in the above form. Then I checked another tutorial, one on how to email the form and changed this form accordingly. Guess I messed up a bit?

Necrolis
15-09-2009, 06:24 AM
I generally use AJAX for forms, but this should help ya a little(i hope...), note, its not neat, as its just from a local testbed of mine:
a little js func I made a autorip a form(for AJAX or whatever else):

function ASYNC_GetFormData(Form)
{
var Form = document.getElementById(FormID);
var Elements = Form.length;
var Data = '';
var TextNext = false;
for(var i = 0; i < Elements; i++)
{
if(Form[i].type == 'text')
{
if(!TextNext)
TextNext = true;
else
Data = Data + "&";

Data = Data + Form[i].name + "=" + Form[i].value;
}
}

return Data;
}

my test form(notice everything is name'd and id'd):

<form id="feedback" action="" method="post">
First Name: <input type="text" name="first"><br>
Last Name: <input type="text" name="last"><br>
Phone: <input type="text" name="phone"><br>
Mobile: <input type="text" name="mobile"><br>
Fax: <input type="text" name="fax"><br>
E-mail: <input type="text" name="email"><br>
Web: <input type="text" name="web"><br>
<input type="button" value="Submit" onclick="ASYNC_POSTSumbitForm('insert.php','feedback','incl uded',true,'');">
</form>

<input type="button" value="Refresh Data" onclick="ASYNC_GETQuery('test.php','included',true);">
<input type="button" value="Clear Data" onclick="ASYNC_ClearData('included',true);">
and the script for inserting:

<?php
include("./include/database.inc.php");

$first = $_POST['first'];
$last = $_POST['last'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$web = $_POST['web'];

$Database = new cDatabase();
$Database->SetTable("contacts");
$Database->Connect();
$Database->Insert("'','$first','$last','$phone','$mobile','$fax','$em ail','$web'");
$Result;
$Rows = $Database->SelectAllEx($Result);
$Database->Close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while($i < $Rows)
{
$first = $Database->GetResult($Result,$i,"first");
$last = $Database->GetResult($Result,$i,"last");
$phone = $Database->GetResult($Result,$i,"phone");
$mobile = $Database->GetResult($Result,$i,"mobile");
$fax = $Database->GetResult($Result,$i,"fax");
$email = $Database->GetResult($Result,$i,"email");
$web = $Database->GetResult($Result,$i,"web");

echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";
$i++;
}

//header('Location: index.php?p=home');
?>so where I do db stuff, you should compact/concat the data to an email and looking at your stuff I think the problem is with your form elements not having a name= attribute