Jump to content


Photo

email w/ php


  • Please log in to reply
11 replies to this topic

#1 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 September 2004 - 03:27 PM

<form method=POST name="email" action="index.php?id=email">
<table>
<tr>
<td>E-mail:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td>Subject:</td><td><select name="subject">
          <option></option>
          <option value="Affiliate Application">Affiliate Application</option>
          -more options removed for space-
        </select></td>
</tr>
<tr>
<td>Comment:</td><td><textarea name="comment" rows="4"></textarea></td>
<tr>
<td><input type="submit" name="submit" value="Send"></td>
</tr></table>
</form>

<?
$at = '@';
$mail = strpos($_POST['email'], $at);

if (isset($_POST['submit'])){
	if (!$_POST['email'] || $mail === false){
   die ("Please use a valid e-mail address");
	}
	if (!$_POST['subject']){
   die ("Please select a subject.");
	}
   
$to = "email edited";
$message = "from: $from<br> comment:<br> $comment";
$subject = $_POST['subject'];
$from = $_POST['email'];
$comment = $_POST['comment'];

$headers .= "To: $to\r\n";
$headers .= "From: $from\r\n";

mail($to, $subject, $message, $headers);
echo "Thank you for your message."; 
} else {
echo "<b>PAGE UNDER CONSTRUCTION, MAIL WON'T ACCTUALLY BE SENT</B>";
}
?>

ok, that's almost the exact code im using as a contact page, i edited out some options and the $to email (to prevent spam)
im running php 4.3.4, apache, and a linux host (all remote, all free)

could anybody tell me why my mail wont send? ive looked at 3 different mail() tutorials, and i even looked at php.net, nothing seams to work

thanks for any help

#2 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 26 September 2004 - 08:20 PM

If this is localhost testing, you need to have a stp server installed to send mail out.

#3 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 September 2004 - 08:30 PM

im running php 4.3.4, apache, and a linux host (all remote, all free)


the server does have an stmp server, not sure about stp, and the host isn't 'localhost'
it's freelinuxhost.com
would that affect anything

#4 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 26 September 2004 - 08:31 PM

I believe you need a smtp server, could be wrong. But I believe it requires one.

#5 Faken

Faken

    Pimpmaster G

  • Admin
  • 5,966 posts
  • Gender:Male
  • Location:Montreal, Canada

Posted 26 September 2004 - 09:28 PM

Any error messages in your logs?

Faken

#6 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 27 September 2004 - 11:01 AM

Look in the main or root directory, or whatever file these documents are stored in and look for a file named error_log. Check for any related errors pertaining to the files your using to run this script.

#7 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 27 September 2004 - 05:45 PM

well, faken, the sites about 2 months old and i haven't really released it, i mean what's it my sig is about it for advertising right now so i haven't set up my error logs (first couple of months... load's of testing, ten times as many errors... you get the point)

and gio, my site does have an stmp server, the email address i have set up on it is admin[at]graphic-designz[dot]uni[dot]cc (replace thie stuff in the '[]'...) it works, i have tested it, i can send and recieve mail through it, just not the mail() function on that one page

anyway, i have set up the error logs, so when they become active i will re-test the function... if it works ill say so, if i don't say anything, presume it didn't work

#8 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 27 September 2004 - 06:25 PM

Just reply when you get the error logs working and tell us what happened.

#9 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 27 September 2004 - 08:40 PM

ok, well just after all the if statements, i changed the variables around to this to see if anything would change
$name = $_POST['name'];	
$email = $_POST['email'];
$subject = $_POST['subject'];
$comment = $_POST['comment'];
$to = "edited";
$message = "This person sent you an email:\n-----\nName: $name\n
      Email: $email\n--------\n
 	 He said:\n\n$comment";
 	 
ini_set(smtp, "smtp.freelinuxhost.com");
$set = mail($to,$subject,$message,"From: $email\n");

echo "Thanks for your time, we will try to contact you as soon as possible.";
} else {
echo "<b>THIS PAGE IS UNDER CONSTRUCTION, MAIL WONT' ACCTUALLY BE SENT</b>";
}
?>
i tested it... nothing changed

also, my error logs aren't quite working, they should have been, ill check back tomorrow and see what's up or contact tech support

thanks for all the help

p.s. i changed the ini_set() to the same smtp host i use to check my mail from hotmail, and it's the almost the same host as my mySQL db (just w/o the smtp part)

#10 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 06 October 2004 - 07:00 PM

$at = '@';
$mail = strpos($_POST['email'], $at);

if (isset($_POST['submit'])){
	if (!$_POST['email'] || $mail === false){
   die("Please use a valid e-mail address");
	}
	if (!$_POST['subject']){
   die("Please select a subject.");
	}
	if (!$_POST['comment']){
   die("Please enter your comment.");
	}

$subj = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$ip = $_SERVER[REMOTE_ADDR];
$to = "mymail's been edited";
$subject = "!MAIL! :$subj:";
$date = date("M j, Y - g:i a");

$headers = "To: Admin \r\n"; 
$headers .= "From: $name <$email>\r\n"; 
$headers .= "Reply-To: $email\r\n";

$body = "Name: $name\r\n
E-Mail: $email\r\n
Comments:\r\n
$comment\r\n\n
---Info---\r\n
IP: $ip\r\n
Date: $date"; 

ini_set(SMTP, "smtp.freelinuxhost.com");
$email = mail($to,$subject,$body,$headers);

if($email === true){
	echo "stuff.";
}else{
	echo "more stuff.";
}
}
?>

dunno what exactly i changed, but for some odd reason the email now works (maybe it's because my host got hit by a hurricane and switched to a new server... i dunno), as for the error logs... they still don't work, my host has issues, but thats nothing that needs to be discussed here

thanks for the help, you can close this now :)

#11 vurtunetech

vurtunetech

    Young Padawan

  • Members
  • Pip
  • 5 posts

Posted 09 November 2004 - 10:33 PM

well first make sure there is an error_log file on your folder, otherwise it won't work.

#12 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 09 November 2004 - 10:41 PM

...you can close this now


i've figured out the error problem also... thanks for helping tho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users