/    Sign up×
Community /Pin to ProfileBookmark

my mailer wont work!

i made this so you can e-mail some one but it wont work! can some one help?
page1
(mailer.php)

[code=php]
<html>
<head>
<title>hi</title>
<?php
$subject = “Form Mail”;
mail( $_GET[‘to’], $subject, $_GET[‘message’] );
?>
</head>
<body>

</body>
</html>
[/code]

page2
(webpage)

[code]
<html>
<head>

<title>Untitled</title>

</head>

<body>
<form action=”http://travis_moore.t35.com/mailer.php” method=”post”>
<input type=”hidden” name=”to” value=”[email protected]”>
<textarea name=”message”>hi there</textarea>
<br><br>
<input type=”submit”>
</form>

</body>
</html>
[/code]

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@BeachSideFeb 04.2005 — ::Edit::

Actually you would want to change this...
[code=php]<?php
$subject = "Form Mail";
mail( $_GET['to'], $subject, $_GET['message'] );
?>[/code]


to this...

[code=php]<?php
$subject = "Form Mail";
mail( $_POST['to'], $subject, $_POST['message'] );
?>[/code]


As using the GET method is not good for email

also I don't think this is correct (I think) [code=php]<textarea name="message">hi there</textarea>[/code]

I think it would have to be like this...

[code=php]<input name="message" type="text" value="Hi there!" />[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 04.2005 — not only is the GET method not good for email, but u declared using the "post" method in your form tag, thats what its not working
&lt;form action="http://travis_moore.t35.com/mailer.php" [b]method="post"[/b]&gt;
Copy linkTweet thisAlerts:
@age13kidauthorFeb 04.2005 — hi again.. for some reason it still wont work even after i changed the GET's to POST's any ideas why it wont work? ps i also changed the textarea to a textbox
Copy linkTweet thisAlerts:
@bokehFeb 05.2005 — This is correct:

<textarea name="message">hi there</textarea>
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 05.2005 — the message should come from a textarea...so your syntax was correct[code=php]<textarea name="message"></textarea>[/code]

then, i just realized whats wrong, u put the php in the <head></head> tags.

try this :
[code=php]
<html>
<head>
<title>hi</title>
</head>
<body>
<?php
$subject = "Form Mail";
$to = $_POST['to'];
$msg = $_POST['message']

if(mail( $to, $subject, $msg )){
echo "Sent mail!";
}else{
echo "failed";
}
?>
</body>
</html>

[/code]
Copy linkTweet thisAlerts:
@age13kidauthorFeb 05.2005 — it shows this error dialog when i try it...
Parse error: parse error, unexpected T_IF in /home/freehost/t35.com/t/r/travis_moore/mailer.php on line 11[/quote]
Copy linkTweet thisAlerts:
@ZealotFeb 05.2005 — Well, since you made a form to mail to people, I'd suggest defining the email address in the php on the send page. A hidden value cant be seen normally, but its there in source, it would be smarter to define it in the php (it keeps your address hidden). Just my 2 cents oh and the $msg = $_POST['message'] needs a ";" after it silly ?
Copy linkTweet thisAlerts:
@BeachSideFeb 05.2005 — [code=php]<textarea name="message"></textarea>[/code]the message should come from a textarea...so your syntax was correct[/QUOTE]

Ah hah! I did not know that I never have used that before ? Learn something new everyday ?
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 05.2005 — oh right that semi-colon! :o :p
Copy linkTweet thisAlerts:
@age13kidauthorFeb 05.2005 — thanks for all your help guys but theere is one more thing i need to know... when i hit submit it went and said "failed" any reason why?
Copy linkTweet thisAlerts:
@age13kidauthorFeb 05.2005 — i also put the semicolon in
Copy linkTweet thisAlerts:
@BeachSideFeb 05.2005 — Try this...

[code=php]
<?php
$to = $_POST['to'];
$subject = "Form Mail";
$msg = $_POST['message'];

return(mail( $to, $subject, $msg ));
?>
[/code]


That will return a true or false depending on sending it''s success.

Also stick that badboy above the doctype so that it is the very first thing processed.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 05.2005 — you could try putting quotes around the variables
Copy linkTweet thisAlerts:
@age13kidauthorFeb 05.2005 — welll i did wat you said but it didnt return true or false :eek:! im so sorry if this is getting annoying but i am realy quite new to PHP
Copy linkTweet thisAlerts:
@BeachSideFeb 05.2005 — if that is not working, you will need to make sure your host allows you to send mail locally because if you can only send mail via SMTP then you might want to look into [URL=http://phpmailer.sourceforge.net/]this[/URL]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 06.2005 — well, no problem, lets do it from scratch...its frustrating ....why isnt it working,..hehehe

HTML:
[code=php]
<html>
<head>
<title>Form mail</title>
</head>
<body>
<form method="post" action="mailer.php">
<input type="hidden" name="to" value="[email protected]">
<br>
<textarea name="message"></textarea>
<br>
<input type="submit" value="Send">
</form>
</body>
</html>

[/code]

Processing file :
[code=php]
<html>
<head>
<title>Sending Mail...</title>
</head>
<body>
<?php
//stocking vars
$to = $_POST['to'];
$message = $_POST['message'];
$subject = "Form mail";

$mail = mail("$to", "Subject : $subject", "$message");

if($mail){
//Success
echo "Your mail has been sent";
}else{
//Failure
echo "Sending failed";
}
?>
</body>
</html>
[/code]


if it still doesnt work, try echoing the vars somewhere, or if it still doesnt work, dont have ur email adress passed by a hidden field, but write it as a string, directly
Copy linkTweet thisAlerts:
@DaiWelshFeb 07.2005 — Most email servers won't accept mail that does not have a from address for obvious (anti-spam) reasons. Depending on how your server is set up the from address may not default, so pass a header for it, e.g.

$mail = mail("$to", "Subject : $subject", "$message","From: {a valid from address for your site}");

if that still does not work then forget all the extra coding and test the mail function directly

$mail = mail("[email protected]", "Test", "Test","From: [email][email protected][/email]");

if even that does not work then talk to your host as they may not allow it or may require additional headers.

HTH,

Dai
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 07.2005 — well, additional headers actually just replace headers that the server send...when u send an email and dont specify additonnal headers, it will say from [email][email protected][/email], so it is actually a valid email, are u sure some email clients will not accept these emails?
Copy linkTweet thisAlerts:
@DaiWelshFeb 07.2005 — It is not the clients that I am talking about (though some may well object, that is a whole other subject) I am saying some mail [B]servers[/B] will not accept mails with no from address, so while the mail server on the host may be quite capable of adding a From: [email][email protected][/email] it may be configured not to (possibly because doing so might risk getting them black-listed?).

I had this problem with a client's host a while back, they had been accepting mails quite happily for some time, but then suddenly started rejecteing it and it turned out it was because the code was not supplying it's own from header and the host had changed their security settings.

At least it is worth trying this since they need a baseline of some working code in order to find where their problem lies or else they need enough ammunition to approach their host with confidence, which means being sure that even the most simple email script possible will not work.

HTH,

Dai
Copy linkTweet thisAlerts:
@bokehFeb 08.2005 — Hi! Are you running this locally on a windows PC?

If the answer to the above is "yes" and you are trying to send via an smtp mail server that requires a username and password (99.99% of them)there is no way to specify these when using php for windows. Anyway if this is the problem [URL=http://www.webdeveloper.com/forum/showthread.php?s=&threadid=55662]read this tread[/URL] to find out how I overcame this problem with Jona's help.
×

Success!

Help @age13kid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...