Jump to content

Newbie: Issue with PHP based Feedback Form Mailer Script


moktoman

Recommended Posts

First of all, I checked the FAQ, couldn't find an answer, then tried a search, which also seemed to turn up nothing, so here I go:

 

I know very little about PHP, and ran into an issue when adding a PHP element to a mostly HTML-based website. I have a contact page in the website I'm working on (link), which is a feedback form script that formats user inputted data into an email and uses another PHP script (class.phpmailer.php) to send  that email to a specific email address. (I hope I described that correctly ???)

 

My problem is that when I enter information into the feedback and submit, I get this response:

 

Message could not be sent.

 

Mailer Error: The following From address failed: blah@blah.com

 

(Note, blah@blah.com is a bogus address that I used for simple test purposes. I was and still am under the assumption that the address entered in that field is not the destination or source address, but an address for the recipient to reply back to upon receiving an email sent from this feedback form, and as such, I though would be irrelevant in the sending of the email)

I looked for and found reference to "From" in the script, but I am not sure where the problem is stemming from.

 

Instead of pasting the entire page's worth of code I'll provide two links to the two scripts in question.

 

Feedback Form Script

PHPMailer Script

 

Other information:

Hosting company - Enom.com

PHP version - to my knowledge, the server is running the most recent version of PHP4

Platform - If you mean my computer's OS, then Windows XP Pro, SP 2

If you are referring to the server's platform, they are Windows-based servers (they do not specify more than that).

 

One other thing. The Feedback Form Script was acquired from my webhost, to use in conjunction with the open source PHPMailer script (phpmailer.sourceforge.net/) they recommended I use.

I scoured the PHPMailer website, but the developer's English is quite rusty, making his documentation more confusing, so I decided coming here would be wiser and more efficient.

 

Thanks in advance for any help you guys can offer me, and if there is any other information I should provide, please let me know!

 

- Michael

Link to comment
Share on other sites

Hi frnd,

          Their is the problem of sending mails using windows server,Also pls check the smtp settings,The same code u used works good with linux,i have posted the same problem in this but could not get  a reply,if i find the reply i will let u know.

Thanks.

Link to comment
Share on other sites

there no problam

gopa_2549  <<<<<<<<<<user

using windows to send mail in php use all the header to send mail via php and your be fine

 

 

an example i use ofthen that works fine.

Another example of sending a utf-8 HTML mail:

$to = 'bob@barnyard.com';
$subject = 'Wakeup bob!';
$message = '<b>yo</b>, whassup?';
$headers = "From: server@barnyard.com\are\n" .
        'X-Mailer: PHP/' . phpversion() . "\are\n" .
        "MIME-Version: 1.0\are\n" .
        "Content-Type: text/html; charset=utf-8\are\n" .
        "Content-Transfer-Encoding: 8bit\are\n\are\n";

// Send
mail($to, $subject, $message, $headers); 

Link to comment
Share on other sites

gopa_2549:

Then why would the server host reccommend to use these scripts if their servers don't support it?

 

redarrow:

I originally had tried to set up a PHP feedback form with the site wizzard's tools, but that did not work correctly either.

 

And that code you posted, I'm not sure how I would implement that into the form code.

 

Speaking of which, here are the two scripts in full form:

 

Feedback Form Page:

<?php

$YourEmailAddress = 'webtester800@gmail.com'; //Email address you want the mail to go to
$Yourname = 'Webmaster'; //Who the email is sent from - this is a name not an email
$MailUsername ='webtester800@gmail.com'; //Email address you are using to send the email
$MailPassword = '******'; //This is the password of the email account used to send the email
$MailServer = 'smtp.gmail.com'; //Assigned mail server
$MailType = 'TEXT'; // Can use HTML or TEXT -case doesn't matter

require("class.phpmailer.php"); //Change this to the real path of the file - this assumes that the mail script
//and the included files are in the same directory


#----------------------- DO NOT EDIT BELOW THIS LINE ------------------------------#

# These are the form Vars - do not edit
$action = $_POST['action'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if(strtolower($MailType) == 'html'){
$mailtypetosend = true;
} else {
$mailtypetosend = false;
}

$mail = new PHPMailer();

$mail->From = $email;
$mail->FromName = $email;
$mail->Host = $MailServer;
$mail->Mailer = "smtp";

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $MailUsername; // SMTP username
$mail->Password = $MailPassword; // SMTP password

$mail->AddAddress($YourEmailAddress, $Yourname);
$mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);

$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML($mailtypetosend); // True for HTML, FALSE for plain text
$mail->SetLanguage("en", "language/");

//Start the page action upon submittal
if ($action == "contact" ) {
if (empty($_POST['name'])) {
$name = FALSE;
$message .= '<br>Please enter your name</br>';
} else {
$name = $_POST['name'];
}
if (empty($_POST['phone'])) {
$phone = FALSE;
$message .= '<br>Please enter a phone number to reach you at</br>';
} else {
$phone = $_POST['phone'];
}
if (empty($_POST['email'])) {
$email = FALSE;
$message .= '<br>Please enter your email address</br>';
} else {
$email = $_POST['email'];
}
if (empty($_POST['comments'])) {
$comments = FALSE;
$message .= '<br>You did not enter in a message</br>';
} else {
$comments = $_POST['comments'];
}

if($comments && $email && $phone && $name){

$mail->Subject = "Contact Us form submitted";
$mail->Body = "A contact us form has been submitted from the website\nHere are the details:\n\n\n";
$mail->Body .= "Name: $name \n";
$mail->Body .= "Phone number: $phone\n";
$mail->Body .= "Email Address: $email\n";
$mail->Body .= "Message: $comments\n\n\n";

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
$sent = 1;
}


echo "<table width=\"622\" border=\"0\" align=\"center\" class=\"table01\">
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Thank you for contacting us, We will respond to all inquiries in the order as they are received, as soon as it is possible.</span></td>
</tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Name: $name</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Email Address: $email</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Phone Number: $phone</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Message: $comments</span></td>
</tr>
<tr>
</table>";
}
}
if(isset($message)) {echo "<center><u><b>$message</span></b></u></center><br>";}

if($sent != 1){
echo "
<table width=\"424\" border=\"0\" align=\"center\" >
<form name=\"form1\" method=\"post\" action=\"$_SERVER[php_SELF]\">
<input type=\"hidden\" name=\"action\" value=\"contact\">
<tr>
<td colspan=\"2\">Contact Form</td>
</tr>
<tr>
<td>Name</td>
<td>
<input name=\"name\" type=\"text\" value=\"$name\">
</td>
</tr>
<tr>
<td>Email Address </td>
<td><input name=\"email\" type=\"text\" value=\"$email\"></td>
</tr>
<tr>
<td>Phone Number </td>
<td><input name=\"phone\" type=\"text\" value=\"$phone\"></td>
</tr>
<tr>
<td height=\"86\">Message / Comments </td>
<td><textarea name=\"comments\" cols=\"30\" rows=\"5\" value=\"$comments\"></textarea>
</td>
</tr>
<tr>
<td height=\"20\" colspan=\"2\"><center><input type=\"submit\" name=\"Submit\" value=\"Submit\"></center></td>
</tr>
</form>
</table>";
}

?>

 

PHPMailer script:

 

See attachment.

 

- Michael

 

[attachment deleted by admin]

Link to comment
Share on other sites

  • 4 weeks later...

Okay, I've worked on this problem for awhile, and got the PHP script to actually send mail to my email address from the server.

 

As it stands: HTML page has form. Data entered into form posts to PHP file that formats it, logins into SMTP server and sends message to itself.

 

That part is fine, but now the emails that the PHP script sends are formatted terribly.

 

The only mention in the script to formatting (so far as I can tell) is this:

 

/* Compose the email. */
if (isset($HTTP_GET_VARS)) {
  while ($a = each($HTTP_GET_VARS)) {
    if ($a[0] == 'From') continue;
    if ($a[0] == 'Subject') continue;
    if ($a[0] == 'Submit') continue;
   $Body  .= $a[0] . "\t= " . $a[1] . "\r\n";
    }
  }
if (isset($HTTP_POST_VARS)) {
  while ($a = each($HTTP_POST_VARS)) {
    if ($a[0] == 'From') continue;
    if ($a[0] == 'Subject') continue;
    if ($a[0] == 'Submit') continue;
   $Body  .= $a[0] . "\t= " . $a[1] . "\r\n";
    }
  }

 

and the right now, the resulting emails look like this:

 

 

Type your message here.Name = blah

Body = Type your message here.

Submit_x = 8

Submit_y = 6

 

 

Any idea what I need to change to make it the email look right?

 

PS - I've attached the full version of the above script to this post.

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Sorry, I still don't quite understand what you're suggesting.

I am very unfamiliar with PHP scripting, so maybe you could give me an example script that implements what you are suggesting...

I tend to learn best from example. :D

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.