Page 1 of 1

PHP mail/contact script misbehaving...

Posted: Sun Jul 15, 2007 6:27 pm
by poomshanka
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello...

I've spent some time pecking around in the forums, using the search, and not finding a specific instance of the problem I'm having. Perhaps I'm missing something, or maybe this bug's an odd one.

I have a PHP contact form on my website:

[url]http://www.bigbrass.com/contact.html[/url]

The code in the page looks like:

[syntax="html"]<form action="http://site.bigbrass.com/forms/email-comments.php" method="post">
<table cellpadding="0" cellspacing="5" border="0">
<tr valign="top">
<td><b>Email:</b></td><td><input type="text" name="email" size="21"></td>
</tr><tr valign="top">
<td><b>Name:</b></td><td><input type="text" name="name" size="21"></td>
</tr><tr valign="top">
<td><b>Subject:</b></td><td><input type="text" name="subject" size="21"></td>
</tr><tr valign="top">
<td><b>Message:</b></td><td><textarea cols="30" rows="6" name="message"></textarea></td>
</tr>
<tr valign="top">
<td>&nbsp;</td><td><input id="subscribe" type="submit" value="&nbsp;Submit&nbsp;"></td>
</table>
</form>
The PHP script looks like:[/syntax]

Code: Select all

<?php

$to = "info@bigbrass.com";
$subject = "Contact Us from Website";
$message = 
"Email: $email\n
Name: $name\n
Subject: $subject\n
Message: $message\n
" ;

if (mail($to, $subject, $message)) {
  header('Location: http://store.bigbrass.com/contact-thankyou.html');
  exit();
} else {

    echo "There was an error while sending the comments.";
}

?>
Everything works great, and the emails come to me with a return address of "webmaster@bigbrass.com". The store itself is hosted on Yahoo.

I tried hijacking the form/code and integrating it into one of my other sites:

http://www.prepresspros.com/contact.html

The code in the page looks like:

Code: Select all

<form action="http://www.prepresspros.com/forms/email-comments.php" method="post">
        <table cellpadding="0" cellspacing="5" border="0">
<tr valign="top">
<td><b>Email:</b></td><td><input type="text" name="email" size="35"></td>
</tr><tr valign="top">
<td><b>Name:</b></td><td><input type="text" name="name" size="35"></td>
</tr><tr valign="top">
<td><b>Subject:</b></td><td><input type="text" name="subject" size="35"></td>
</tr><tr valign="top">
<td><b>Message:</b></td><td><textarea cols="35" rows="8" name="message"></textarea></td>
</tr>
<tr valign="top">
<td>&nbsp;</td><td><input id="subscribe" type="submit" value="&nbsp;Submit&nbsp;"></td>
</table>
</form>
The PHP script looks like:

Code: Select all

<?php

$to = "pros@prepresspros.com";
$subject = "Contact from Prepress Pros website";
$message = 
"Email: $email\n
Name: $name\n
Subject: $subject\n
Message: $message\n
" ;

if (mail($to, $subject, $message)) {
  header('Location: http://www.prepresspros.com/thankyouinset.html');
  exit();
} else {

    echo "There was an error while sending the comments.";
}

?>
There are only a couple areas I tweaked, namely those to do with destination email, script location, subject line and "thank you" page location. As far as I can tell, no code was altered.

The emails from this script come to me with a return email address of "anonymous@72-4-174-76.ptr.primarydns.com", and the user-supplied fields (Email, Name, Message) are all blank. Problems would be the odd return email address, and the fact that the user-supplied fields are blank. I'd also like to remove the default subject ("Contact from Prepress Pros website"), as it's also being placed in the Subject field in the user-supplied data area. Actually, with this problem script, that's the only piece of info that comes through.

What am I missing here? Thank you very much in advance for your time...

...Dave

p.s. Thanx to Feyd for cleaning up my post. I don't think I could've done that even if I tried. I've never had to use PHP before, and was only able to work with this code because someone first implemented it, then I went in and changed things that looked familiar to me (email addresses, http locations, etc.).


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Jul 15, 2007 8:23 pm
by harrisonad
maybe the "sendmail_from" on php.ini is not set correctly, so it's using the host's default email

Posted: Sun Jul 15, 2007 9:18 pm
by poomshanka
harrisonad wrote:maybe the "sendmail_from" on php.ini is not set correctly, so it's using the host's default email
Hmmm... a little fishing around on The Google turned up some rather complex info on what a php.ini file is. This info is way over my head. I can push pixels to within an inch of their life in Photoshop, but this code stuff is a quite beyond me. I don't have anything even remotely approaching a rudimentary understanding of PHP, and was really just hoping to get lucky when I tried pulling these email form shenanigans.

Is there a directory on a server where the php.ini file typically lives? I did some poking around and found nothing. The other possible option is to pay someone to work this out for me. Would it be appropriate to post a "help wanted" here?

Thanx...

...Dave

Posted: Sun Jul 15, 2007 9:29 pm
by harrisonad
if your site is hosted to a hosting company, you can't physically have contact with the server's php.ini
but you can use ini_set() function to tweak most of php.ini configurations.
anywhere in your emailing script, type:

Code: Select all

ini_set('sendmail_from','myown@email.com');

Posted: Sun Jul 15, 2007 9:37 pm
by poomshanka
harrisonad wrote:if your site is hosted to a hosting company, you can't physically have contact with the server's php.ini
but you can use ini_set() function to tweak most of php.ini configurations.
anywhere in your emailing script, type:

Code: Select all

ini_set('sendmail_from','myown@email.com');
Hmmm... no dice on that one. Strange that this wasn't a problem on the site I borrowed the code from. Perhaps I'll have to touch base with the programmer who integrated that for me.

Thanx, though...

:D

...Dave