...

View Full Version : emails in php



habib
03-17-2003, 03:05 PM
Hi all,

I am trying to send an email in php but I keep getting error messages. Below is my code and error message:

the code----

<?php

$message="test blah blah blah";
mail("habibrazak@yahoo.co.uk","Test Email in PHP", $message);

?>

The error message I am getting is:

Failed to Connect in c:\phpdev\www\test\thankyou.php on line 14

Any ideas why I am getting this error???

HR

sleepingdanny
03-17-2003, 03:24 PM
Did you told the form to...
<form action="..."> ?? If so delete what you printed in the action place...

You can try to send the user to a thank you page after the email is sent with this code... :thumbsup:


<?php

$message="test blah blah blah";
$mail=mail("habibrazak@yahoo.co.uk","Test Email in PHP", $message);
if($mail){
header("location: http://.../thankyou.php");}
if(!$mail){
print "ERROR...";}

?>

Remember that if you use the header function the code has to be placed above the <html> tag or it will show an error!

habib
03-17-2003, 03:58 PM
Hi Sleeping Danny,

I am not using forms to send the email in php. Must I use forms to send emails?

What I am trying to achieve is use values for certain variables from a text file (firstly, is this possible?) and then send these values via email to myself. The recepient email address, subject, will always stay the same. I tried to use the mail function (look at first posting above) in my thankyou.php page, when the page loads it should send me an email with the test data. But I keep getting errors.

If anyone knows how I can send an email with dummy fields or data - greatly appreciated.

Also can someone confirm whether I need to have a form in order to send an email - I am under the assumption that the mail() can be used anywhere, irrespective of a form.

Once again thankyou for your help.

Nightfire
03-17-2003, 05:27 PM
It failed because you haven't got an smtp server on your pc, and no, you don't need to use a form at all if you're sending a preset email, like "welcome to my site ... thanks for joining" etc, if you're wanting ppl to send you emails, then you'd need a form

I believe php-gtk is an smtp server? Firepages is creating this app, so maybe he can fill you in with what it is/does

habib
03-18-2003, 09:35 AM
Thankyou NightFire,

That makes sense now, I uploaded the page to my host and yes that works fine.

X c lent

P.s I have 3 pages which have forms on them, these fields are then passed on from one page to the next page and on the final page the details are confirmed. If I want to use the values for these variables in my email how would I do this?

I.e :User enters in their contact details and these fields are passed on to products.php where the user selects a product.
These details are passed on to confirm.php where the details are echoed out for the user to confirm. When the user clicks next the thankyou.php page is shown and an email is sent to me with the user contact details and products chosen.

Thanks

Eternity Angel
03-19-2003, 02:36 AM
This same thing is happening with me. I do not have a SMTP server.

Does anyone know where a good one is, and how I could configure PHP to use it?

(Maybe it'd help habib too :-p)

Nightfire
03-19-2003, 10:30 AM
This sometimes works, but most the time it won't. Find the php.ini file, open that up and then search for (it's around line 579)

[mail function]
; For Win32 only.
SMTP = localhost

Change localhost to your ISP smtp address, like

[mail function]
; For Win32 only.
SMTP = mail.myisp.com

x_goose_x
03-22-2003, 05:33 AM
but what if your ISP requires authentication?

krycek
03-22-2003, 09:42 AM
you guys desperately need my SO_MAIL script :p

It replaces mail() and lets you set loads of stuff

I have attached v1.3 however v1.4 will be complete in the next day or so, and v2.0 by the end of next week, because I have to do some extras for a client :)

enjoy! :D

::] krycek [::

krycek
03-22-2003, 09:43 AM
I could only upload one file at a time, plus I had to put .txt on the end. Please remove the .txt :)

Here is the configuration script for that email() function

::] krycek [::

krycek
03-22-2003, 09:46 AM
OK, I use this stuff extensively and I have not had any bugs, but if you do have any then please tell me. Can anyone who downloads and uses my code also keep me posted, because I would love to know who uses this stuff :)

Broken down versions of this script have already appeared in certain places and there's no way to prove it was from my script, but it's fishy... :p basically if you see a script like this it's likely to have come from me in some form at some time, because I have been developing this mailer for a while :)

Have fun! :D

::] krycek [::

krycek
03-22-2003, 09:52 AM
Oh yeah, also, I use SciTE to develop a lot of my code nowadays, because I have modded the distribution so that the syntax colouring is more to my liking ;)

I include a screenshot here for your viewing pleasure! :p (I can't attach it, it's too big lol)

www.soapi.com/scite_screenshot.gif

If you want my custom SciTE settings, just ask :D

::] krycek [::

krycek
03-25-2003, 03:29 AM
I notice that 7 people have downloaded the mail functions, but no-one has downloaded the config script...

you need BOTH, people! or else it will not work :rolleyes:

::] krycek [::

Nightfire
03-25-2003, 07:53 AM
lol

I just got scite for using with c++, it's a nice editor :) Use it for everything now and got rid of editpad classic after 3 years :o

sarah
04-02-2003, 01:56 PM
Hi all, I followed the above method to send emails in php - thanx Habib n Firepages. I know want to take this one step further. I send an email using the following code:

<? php
if ($products=="yes") {
$to="products@sarah.mydomain.com";
$subject="Product Info you required";
$message.="Hi, blah blah blah.....";
}

if($geninfo=="yes") {
$to="enquiries@sarah.mydomain.com";
$subject="General Enquiry";
$message.="Hi, blah blah blah.....";
}

mail($to, $subject, $message);

At the moment depending on which variable is passed I get the relevant email. I now want to send myself one type of email (i.e using above code), and send the sender a confirmation email - this would have a different subject, body text, etc.

What is the best way of doing this?
(would i use $Bcc or is there a better way to do this?)

Sarah

sarah
04-04-2003, 03:25 PM
so any ideas ppl?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum