View Full Version : Send a mail with php?
Hi there, I need to send a mail of the "Jhon Smith Invites you to see this page..." kind. I know I can send mail messages from php, but I donīt know how.
Any help will be usefull, Thnx.
Dylan Leblanc
01-13-2003, 09:01 PM
Use the mail() function. http://www.php.net/manual/en/function.mail.php
Thnx I know that function sends mails, but what I don't know is what and how I configurate php to do it...
cg9com
01-14-2003, 12:40 AM
you could search a site like http://www.hotscripts.com for a free php mailer script, if thats all your looking for.
is configurate a word wert?
Stoffel
01-19-2003, 08:55 PM
mail("joecool@example.com", "My Subject", "Line 1\nLine 2\nLine 3");
Its a nice script, but how do i have to use it in a form.
I have a lot of date it has to send to me, how do I let the script know what he has to send to me?
(For example: in a form I ask a name, adress and some text about you. I name them as Name, Adress, and AboutMe, and these 3 values has to be send to my email adress)
Found it already
http://www.codingforums.com/showthread.php?s=&threadid=13077
firepages
01-20-2003, 01:39 AM
if your form went along the lines of ...
<form name="bella" method="POST" action="mail.php">
<input type="text" name="name"><br />
<input type="text" name="address"><br />
<textarea name="about_me"><br />
<input type="submit" name="submit">
</form>
and mail.php looked a little like this....
<?php
if($_POST['submit']){
$msg ='name ::'.$_POST['name']."\n";
$msg .='name ::'.$_POST['address']."\n";
$msg .='name ::'.$_POST['about_me']."\n";
if(mail("joecool@example.com", "My Subject",$msg)){
$rets="message sent<br />";
}else{
$rets="message not sent<br />";
}
}
?>
<html>
<body>
<?php echo $rets;?>
</body>
</html>
?>
then you would have a very basic but working form !
Stoffel
01-20-2003, 03:57 PM
Thanx a lot
Now I know how to do it
I am new to this so I have an other question
can the message ("message sent" and "message not sent") be changed by a html page?
firepages
01-20-2003, 04:21 PM
Sorry, I dont quite understand what you mean ?
Stoffel
01-20-2003, 04:25 PM
When the users clicked the send button, they will be directed to a page with the text "Message sent"
Can that be changed in a html page I already made? (for example, can it be changed in the page thnx.html)
Jeewhizz
01-20-2003, 04:47 PM
Sure it can!
change this
if(mail("joecool@example.com", "My Subject",$msg)){
$rets="message sent<br />";
}else{
$rets="message not sent<br />";
}
to this
if(mail("joecool@example.com", "My Subject",$msg)){
include("done.html");
}else{
include("error.html");
}
remember to remove the <?php echo $rets;?> bit as well if you use the snippet to include html files ;)
Stoffel
01-20-2003, 05:20 PM
Thnx!!
So this should be the final code?
<?php
if($_POST['submit']){
$msg ='name ::'.$_POST['name']."\n";
$msg .='name ::'.$_POST['address']."\n";
$msg .='name ::'.$_POST['about_me']."\n";
if(mail("joecool@example.com", "My Subject",$msg)){
include("done.html");
}else{
include("error.html");
}
}
?>
PS: how do i put an empty rule into the message?
(how do I get this
'name'
'adress'
)
bored
01-20-2003, 06:58 PM
Use hard returns:
\r\n - equivalent to <br> with html.
\r\n\r\n - equivalent to <br><br> with html.
Example:
$test = "Test\r\n\r\nTest";
That would output:
Test
Test
Hope that helped.
Stoffel
01-20-2003, 09:11 PM
Thnx a lot
Now I've got one final question
Its not realy PHP but ...
I am making a form,
people have to fill in all sort of things, then they have to push on the "Next" button and then they will be brought to a new html page where everything they filled in is sommed up.
And then they can push the submit button to send me the mail
(for example: on the first page they fill in there name and adress and then they push the next button. They will arrive on a new page with the text:
Your name: name
your adress: adress
Are u sure these are right then push "submit")
Will the mail.php still work or do I have to put some extra text
(some sort of <input type=hidden..., but how can i make sure that it knows what the name is and what the adress is?)
Hope u understand what I am trying to explain
bored
01-20-2003, 10:27 PM
Use hidden values.
Hi there I have this script :
<?php
$message = "Este es el mensaje.";
if(mail("wert@eranor.com", "the subject", $message))
{
echo("message sent");
}
else
{
echo("Message not sent");
}
?>
and I got this error:
Warning: Failed to Connect in C:\Inetpub\wwwroot\wert\Prueba.php on line 2
Message not sent
How can I specify the mail acount's password?
bored
01-23-2003, 03:50 AM
It couldn't connect to the mail server.
zoobie
01-23-2003, 06:38 AM
You'd need a whole new script for checking your mail account with a password. You're probably getting the error because it's trying to send and maybe you're not on the internet?
firepages
01-23-2003, 07:53 AM
if your mailserver requires authentication then you wont be able to send mail like that... (some mailservers do some dont ~)
but you can
a) get your own mailserver (search for mercury mail / pegasus) or
b) goto hotscripts.com and get an SMTP email script that includes authentication, there are a few good ones there.
Stoffel
01-23-2003, 06:54 PM
Hiya
I tried the php script, but it doesn't work
Every time I want to send the form, the script doesn't send the mail and redirects me to nothing (source is almost empty, except for the ads)
And I know that my server is php enabled because I doublechecked it
Here is a part of the code:
<?php
if($_POST['submit']){
$msg ='name ::'.$_POST['titel']."\n";
$msg .='name ::'.$_POST['voornaam']."\n";
$msg .='name ::'.$_POST['voorvoegsel']."\n";
$msg .='name ::'.$_POST['naam']."\n";
$msg .='name ::'.$_POST['straat']."\n";
$msg .='name ::'.$_POST['huisnummer']."\n";
$msg .='name ::'.$_POST['woonplaats']."\n";
$msg .='name ::'.$_POST['provincie']."\n";
$msg .='name ::'.$_POST['email']."\n";
$msg = "\r\n\r\nDe films\r\n";
$msg .='name ::'.$_POST['filmnaam1']."\n";
...
$msg .='name ::'.$_POST['prijscd2']."\n";
if(mail("ceekay@myrealbox.com", "Movie Palace Aankoop",$msg)){
include("done.html");
}else{
include("error.html");
}
}
?>
(I left a part of the script out of the script, ... is that part because its the same text as the above)
Does anyone sees something wrong?
So I can't use mail() function for this. There are not such parameter for username and password.
Does any one know where to find that script firepages says I can found in hotscripts.com?
thnx
zoobie
01-24-2003, 01:21 AM
Just because the php is enabled doesn't mean the mail() is enabled. Most free hosts don't have it enabled...but this one does...Try www.9cy.com & different email accounts, too. Should work...:D
PS - That code looks pretty strange...
Stoffel
01-24-2003, 03:53 PM
PS - That code looks pretty strange...
Yeah I know, but thats just for testing it.
PS: thnx for the link
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.