Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail question 2

Status
Not open for further replies.

ascikey

Programmer
Feb 18, 2004
127
GB
I would like to send mail via a php scrip but do I have to install a mail server?

Sorry if this is a silly question. I have already written a simple script but it fails and I think this maybe the reason.
 
Yes and no.
More info about your OS would be helpful to answer the question completely.
 
sorry i am doing 2 jobs at once it is windows xp
 
Windows - quoting the PHP manual at
SMTP string

Used under Windows only: DNS name or IP address of the SMTP server PHP should use for mail sent with the mail() function.
smtp_port int

Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25. Only available since PHP 4.3.0.

That sort of makes me belive that you need an SMTP server either somwhere running on your windows box or somwhere else.
 
Hi DRJ478, I installed a free smtp server and it worked great thanks.

When the mail was sent the email had the from address that was supplied in the php.ini file, is it possible to alter this address at run time.

I have looked at the page and it seems to be stored in the variable sendmail_from but I don’t know how to access it or even it can be accessed
thanks for you help.
 
Code:
<?php
$sendTo = "info@email.com";
$subject = "Message received from the Info Site";

/* header information not including sendTo and Subject
 these all go in one variable.  First, include From:*/
$headers = "From: " . $_POST["name"];
$headers .= "<" . $_POST["email"] .">\r\n";
// next include a Reply-To:
$headers .= "Reply-To: " . $_POST["email"];

$message = $_POST["message"];


// send the mail!
mail($sendTo, $subject, $message, $headers);
?>


ps. I did not write this code, I meerly removed some commenting.

I found it in this thread:
 
hmm that is similar as the one i am already using but the from i s ignored and the from in the php.ini is used. this is what i am using

Code:
<?php
$headers = "from asmtony@ses.co.uk";
$toEmail = "some@yahoo.co.uk";
$myMessage = "Hi  me, Just testing out an email system on my com ";
$mySubject = "Hi T";
mail($toEmail, $mySubject, $myMessage, $headers);
print "<h1> mail has been sent </h1>"; 
?>

but the from asmtony@se.co.uk is not shown the one that is shown is asm@se.co.uk which is in the php.ini file in a var called sendmail_from. but dont know how to access it?
 
hmm right.. that worked great DaButcher (strange name lol) thanks, just need to have a look at why but thanks for the script it was really helpful. A * for ur script.
 
Here's the explanation why:

According to RFC2822 (Internet Message Format) each of the originator fields has to end with a CRLF (carriage return, line feed):
from = "From:" mailbox-list CRLF

sender = "Sender:" mailbox CRLF

reply-to = "Reply-To:" address-list CRLF
Your code has no CRLF separators, thus the extra headers cannot be interpreted correctly.
 
Thank you for the star :)
As far as my nick goes, I've had it since I started playing LAN games back in the 90's..

I wanted to change my nick several times, but every time I do, all the people I've known over IRC start whining.

Good luck with your script :)

Sincerely,
Olav Alexander Mjelde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top