Sending e-mail

Sending e-mail

Postby Administrator » Tue Mar 13, 2007 3:25 am

Sendmail program is disabled at http://www.athost.net. Users must use SMTP with authentification.

This sample uses the Pear Mail package (already in INCLUDE path).
http://pear.php.net/package/Mail
Code: Select all

<?
include_once("Mail.php");

$recipients = 'mail_to@domain.mail';

$headers["From"] = 'YourAccount@athost.net';
$headers["To"] = 'mail_to@domain.mail';
$headers["Subject"] = "Test message";

$body = "TEST MESSAGE!!!";

$params["host"] = 'mail.athost.net';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'YourAccount@athost.net';
$params["password"] = "YourPassword";

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);

$mail_object->send($recipients, $headers, $body);

echo "Email sent."
?>


These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.
Administrator
Site Admin
 
Posts: 8
Joined: Tue Mar 13, 2007 2:27 am

Postby tracer » Thu Jun 07, 2007 12:17 am

Hi I have try this And it doesnt work, I create my php file and put it on the public folder. I test it calling the php like this mynamesite.athost.net/myphpfile.php

It doesnt work any idea?

message shown:

Fatal error: Class 'Mail' not found in /usr/local/data/www/net.athost.vhosts/k/mynamesite.athost.net/public_html/sendmail.php on line 25

Thanks for your time
tracer
 
Posts: 1
Joined: Thu Jun 07, 2007 12:15 am

Postby Support (John) » Mon Jun 11, 2007 1:02 pm

Please try again this script. The problem with sending e-mails via PHP has already been resolved.
Sorry for any inconveniences caused.
Support (John)
 
Posts: 34
Joined: Tue Mar 13, 2007 2:56 am

Postby Dark_Zero » Mon Jul 09, 2007 10:07 pm

Hi, what does this mail function do? does it let users send email to the admin if they have an email account at yahoo.com?
Dark_Zero
 
Posts: 7
Joined: Mon Jul 09, 2007 10:06 pm
Location: California, USA

Postby Support (John) » Thu Jul 19, 2007 12:16 pm

Yes, it does.
Support (John)
 
Posts: 34
Joined: Tue Mar 13, 2007 2:56 am

Re: Sending e-mail

Postby Tal » Thu Oct 02, 2008 5:17 am

---> no error but email was not received. Any suggestion? Thanks!

include('/usr/local/share/pear/Mail.php');
$recipients = 'recipient@recipient.com';

$headers["From"] = 'YourAccount@athost.net';
$headers["To"] = 'recipient@recipient.com';
$headers["Subject"] = "Test message";

$body = "TEST MESSAGE!!!";

$params["host"] = 'mail.athost.net';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'ndb@athost.net';
$params["password"] = 'mypasswordforthisaccount';

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);

if ( $mail_object->send($recipients, $headers, $body)){
echo "Email sent...";
}else{
echo 'error';
}

---> no error but email was not received. Any suggestion? Thanks!
Tal
 
Posts: 2
Joined: Thu Oct 02, 2008 5:13 am

Re: Sending e-mail

Postby Support (John) » Thu Oct 02, 2008 8:02 am

If your account is test_site.athost.net and password is 123456, you should use following script:

<?
include_once("Mail.php");

$recipients = 'mail_to@domain.mail';

$headers["From"] = 'test_site@athost.net';
$headers["To"] = 'mail_to@domain.mail';
$headers["Subject"] = "Test message";

$body = "TEST MESSAGE!!!";

$params["host"] = 'mail.athost.net';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'test_site@athost.net';
$params["password"] = "123456";

$mail_object =& Mail::factory("smtp", $params);

$mail_object->send($recipients, $headers, $body);

echo "Email sent."
?>
Support (John)
 
Posts: 34
Joined: Tue Mar 13, 2007 2:56 am

Re: Sending e-mail

Postby Tal » Fri Oct 03, 2008 6:10 am

Thanks!
Tal
 
Posts: 2
Joined: Thu Oct 02, 2008 5:13 am

Re: Sending e-mail

Postby norwichchris » Wed Apr 01, 2009 1:29 pm

Hi,
I have an urgent problem my Email server doesn't work at all. I tried two PHP based forms to send emails and neither worked. My aim is to create a PHP postcard script: I have changed my CHMOD settings already as suggested by someone else.

My account name is:
norwichchris.athost.net

Code below:

Code: Select all
#
<?php
#
/*************************************************
#
* Micro Postcard
#
*
#
* Version: 1.0
#
* Date: 2007-07-10
#
*
#
* Usage:
#
* Step 1.
#
* Copy your normal sized image into the images directory
#
* and the thumbnails with the same name into the thumbs directory.
#
* We recommend to use 640x480 for normal images and
#
* 128x96 for thumbnails.
#
*
#
* Step 2.
#
* Edit the senderName and senderEmail to a valid name and email.
#
*
#
* Step +1.
#
* Set the postcardURL to the URL where you installed the script
#
* if the address in the email is invalid.
#
*
#
****************************************************/
#

#
// CHANGE PARAMETERS HERE BEGIN
#
$columns = 5;
#
$senderName = 'chris postcards'; // Eg.: John's Postcards
#
$senderEmail = 'chris@pearce.net'; // Eg.: john@postcard.com
#
// Change only if you have problems with urls
#
$postcardURL = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
#
// CHANGE PARAMETERS HERE END
#

#

#

#
// This function displays the available images
#
function displayPhotos(){
#
global $columns;
#
#
$act = 0;
#
// Open the actual directory
#
if ($handle = opendir("thumbs")) {
#
// Read all file from the actual directory
#
while ($file = readdir($handle)) {
#
if (!is_dir($file)) {
#
if ($act == 0) echo "<tr>";
#
echo "<td align='center'><img src='thumbs/$file' alt='postcard' /><br/><input type='radio' name='selimg' value='$file' /></td>";
#
$act++;
#
if ($act == $columns){
#
$act = 0;
#
echo "</tr>";
#
}
#
}
#
}
#
echo "</tr>";
#
}
#
}
#

#
?>
#
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
#
<html>
#
<head>
#
<title>Micro Postcard</title>
#
<link href="cardidea/style/style.css" rel="stylesheet" type="text/css" />
#
</head>
#
<body>
#
<div id="main">
#
<div id="caption">Micro Postcard</div>
#
<?php if ( (!isset($_POST['submit'])) && (!isset($_GET['show'])) ) { ?>
#
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
#
<table align="center">
#
<?php displayPhotos(); ?>
#
</table>
#
<h2>Fill the form</h2>
#
<table width="100%">
#
<tr><td>Send to (email address):</td><td><input type="text" name="email" size="30"/></td></tr>
#
<tr><td>Message:</td><td><textarea name="message" rows="10" cols="40"></textarea></td></tr>
#
<tr><td colspan="2" align="center"><input type="submit" value="Send card!" name="submit"/></td></tr>
#
</table>
#
</form>
#
<?php } else if ( (isset($_POST['submit'])) && (!isset($_GET['show'])) ) {
#
$pic = isset ($_POST['selimg']) ? $_POST['selimg'] : '';
#
$filename = date('YmdGis');
#
$f = fopen('messages/'.$filename.".txt","w+");
#
fwrite($f,$pic."\n");
#
fwrite($f,$_POST['email']."\n");
#
fwrite($f,htmlspecialchars($_POST['message'])."\n");
#
fclose($f);
#
#
// Compose the mail
#
$from = "From: $senderName <$senderEmail>\r\n";
#
$replay = "Reply-To: $senderEmail\r\n";
#
$params = "MIME-Version: 1.0\r\n";
#
$params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
#
$mailtext = "You have just received a virtual postcard!\r\n\r\n"
#
. "You can pick up your postcard at the following web address:\r\n"
#
. "$postcardURL"."?show=$filename\r\n\r\n"
#
. "We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n"
#
. "Regards,\r\n"
#
. "MicroPostcard\r\n"
#
. $postcardURL;
#
#

#
// Send email
#
@mail($_POST['email'],"You've received a postcard",$mailtext,$from.$replay.$params);
#

#
?>
#
#
<center>
#
Your postcard was sended succesfuly!<br/><br/>
#
<img src='images/<?php echo $pic; ?>' alt="postcard" /><br/><br/><br/><?php echo nl2br(htmlspecialchars($_POST['message'])); ?></center>
#
<?php } else if ( (!isset($_POST['submit'])) && (isset($_GET['show'])) ) {
#
$file = isset($_GET['show']) ? $_GET['show'] : '' ;
#
$content = file('messages/'.$file.".txt");
#
$pic = $content['0'];
#
unset ($content['0']);
#
unset ($content['1']);
#
$main = "";
#
foreach ($content as $value) {
#
$main .= $value;
#
}
#
?>
#
<center>
#
Your postcard!<br/><br/>
#
<img src='images/<?php echo $pic; ?>' alt="postcard" /><br/><br/><br/><?php echo nl2br(htmlspecialchars($main)); ?></center>
#
#
<?php } ?>
#
<div id="source">Micro Postcard 1.0</div>
#
</div>
#
</body>


This script was downloaded from another site and i am testing it out to see if it works.

any help would be much appreciated

chris
norwichchris
 
Posts: 2
Joined: Mon Mar 30, 2009 4:09 pm

Re: Sending e-mail

Postby Support (John) » Thu Apr 09, 2009 8:06 am

Please read following link e-mail script example.
Support (John)
 
Posts: 34
Joined: Tue Mar 13, 2007 2:56 am

Re: Sending e-mail

Postby bruce747 » Wed Mar 24, 2010 10:09 pm

Support (John) wrote:If your account is test_site.athost.net and password is 123456, you should use following script:

<?
include_once("Mail.php");

$recipients = 'mail_to@domain.mail';

$headers["From"] = 'test_site@athost.net';
$headers["To"] = 'mail_to@domain.mail';
$headers["Subject"] = "Test message";

$body = "TEST MESSAGE!!!";

$params["host"] = 'mail.athost.net';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'test_site@athost.net';
$params["password"] = "123456";

$mail_object =& Mail::factory("smtp", $params);

$mail_object->send($recipients, $headers, $body);

echo "Email sent."
?>


good day. i'm new here. i have followed this, replacing the appropriate values for username and password. I got no error and the message Email sent. is shown but still the email is not sent at my yahoo account. Hope you can help.
bruce747
 
Posts: 2
Joined: Wed Mar 24, 2010 10:04 pm

Re: Sending e-mail

Postby Support (John) » Thu Mar 25, 2010 8:30 am

You should check Junk folder in your yahoo email.
Support (John)
 
Posts: 34
Joined: Tue Mar 13, 2007 2:56 am

Re: Sending e-mail

Postby bruce747 » Tue Mar 30, 2010 1:44 pm

Support (John) wrote:You should check Junk folder in your yahoo email.


thanks my bad. Got some typo in my code. it's ok now.
bruce747
 
Posts: 2
Joined: Wed Mar 24, 2010 10:04 pm


Return to PHP Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron