I’m attempting to send email with a PHP application I got from a textbook. Do I need to start an email server in order to get the application to work?
Using SuSE 11.2
No.I use it to notify me of search queries that don’t return a result, and I
don’t recall specifically installing an email server. What is the PhP code
you’re trying to use?
Here’s what I use.
$subject = “dictionary search”;
$message = "The following search string gave no results.
";
$message .= “$search_string”;
$headers = “From: myaddress@domain.xyz”;
mail(“recipient@domain.xyz”, $subject, $message, $headers);
Parthenolide wrote:
>
> I’m attempting to send email with a PHP application I got from a
> textbook. Do I need to start an email server in order to get the
> application to work?
> Using SuSE 11.2
>
>
Here are the programs as requested. I think the problem is that the code does not pass SMTP login data and sever info to the host website.
file postcard.php:
<html>
<head>
<title>Enter E-mail Data</title>
<body>
<form name=“theform” method=“post” action=“sendmail.php”>
<table>
<tr>
<td>To:</td>
<td><input type=“text” name=“to” size=“50”></td>
</tr>
<tr>
<td>From:</td>
<td><input type=“text” name=“from” size=“50”></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type=“text” name=“subject” size=“50”></td>
</tr>
<tr>
<td valigh=“top”>Message:</td>
<td><textarea cols= =“60” rows=“10” name=“message”>Enter your message here</textarea>
</td>
</tr>
<td></td>
<td>
<input type=“submit” value=“Send”>
<input type=“reset” value=“Rest the form”>
</td>
</table>
</body>
</html>
file sendmail.php
<html>
<head>
<title>Mail Sent!</title>
<body>
<?php
$to = $_Post"to"];
$from = $_Post"from"];
$subject = $_Post"subject"];
$message = $_Post"message"];
$headers = “From:” . $from . "
";
$mailsent = mail($to, $subject, $message, $headers);
if ($mailsent) {
echo “Congrats! The following message has been sent: <br><br>”;
echo “<b>To:</b> $to<br>”;
echo “<b>From:</b> $from<br>”;
echo “<b>Subject:</b> $subject<br>”;
echo “<b>Message:</b><br>”;
echo $message;
} else {
echo “There was an error…”;
}
?>
</body>
</html>
I may have been wrong. There is an email server configured on my server. It
hasn’t been used except for testing, and that was a long time ago.
Your code looks fine. It should work if you’re seeing the right POST
information in the echo statements at the bottom. The host server may
require that the “from:” field be set to the email address that it has for
the person the service is registered to (for good reason). You might contact
the host of the site and see what they require. I wish I could help more,
but it seems I’ve just been lucky here. Your code is fine though.
Parthenolide wrote:
>
> Here are the programs as requested. I think the problem is that the code
> does not pass SMTP login data and sever info to the host website.
>
> file postcard.php:
>
> <html>
> <head>
> <title>Enter E-mail Data</title>
> <body>
> <form name=“theform” method=“post” action=“sendmail.php”>
> <table>
> <tr>
> <td>To:</td>
> <td><input type=“text” name=“to” size=“50”></td>
> </tr>
> <tr>
> <td>From:</td>
> <td><input type=“text” name=“from” size=“50”></td>
> </tr>
> <tr>
> <td>Subject:</td>
> <td><input type=“text” name=“subject” size=“50”></td>
> </tr>
> <tr>
> <td valigh=“top”>Message:</td>
> <td><textarea cols= =“60” rows=“10” name=“message”>Enter your
> message here</textarea>
> </td>
> </tr>
> <td></td>
> <td>
> <input type=“submit” value=“Send”>
> <input type=“reset” value=“Rest the form”>
> </td>
> </table>
> </body>
> </html>
> -------------------------------------------------------
> file sendmail.php
> <html>
> <head>
> <title>Mail Sent!</title>
> <body>
> <?php
> $to = $_Post"to"];
> $from = $_Post"from"];
> $subject = $_Post"subject"];
> $message = $_Post"message"];
>
> $headers = “From:” . $from . "
";
>
> $mailsent = mail($to, $subject, $message, $headers);
> if ($mailsent) {
> echo “Congrats! The following message has been sent: <br><br>”;
> echo “<b>To:</b> $to<br>”;
> echo “<b>From:</b> $from<br>”;
> echo “<b>Subject:</b> $subject<br>”;
> echo “<b>Message:</b><br>”;
> echo $message;
> } else {
> echo “There was an error…”;
> }
> ?>
> </body>
> </html>
>
>
I think the command I need use is mail::factory().
It is contained in the PEAR library. Its 5th argument is a string of parameters the turn the email request into a STMP function. It also allows for the STMP user name and password to persist allowing for efficiently embedding the mail::factory() command within a loop.
Actually, the PHP.function ‘mail’ should be enough ,but it need a running mail-server like postfix or sendmail.
If they are not activated ( as they are normally on a webserver ) your mail gets stuck until the mailserver is started.
You won’t need any SMTP-auth since the are sent from the machine which runs the mail server.
Using PEAR packets is kinda risky, since some providers do not allow to load additional libraries.
I recommend to use PHP: Hypertext Preprocessor as reference