473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Send email from the server by PHP

hsriat
1,654 Expert 1GB
When a user registers with the website or when he requests to generate a new password, I need to send an email to the user containing some welcome message or his requested information (respectively) as you would have seen on many websites.

What do I need to do for that? I mean, I know the use of mail() function, but what changes do I need to do in php.ini file and how can I configure the email address which will send the emails?

I'm at the verge of project completion, so too tired to do any research.
Can anyone point me to the right direction? Or any tutorials?

Thanks
Apr 30 '08 #1
11 2629
Atli
5,058 Expert 4TB
Hi.

To use the mail() function you would have to edit the [mail function] portion of you php config.

However, there are better alternatives to the mail function, like for example PHPMailer and Swift Mailer.
Apr 30 '08 #2
hsriat
1,654 Expert 1GB
Thank you for the links.
They are really helpful.

:)

Regards,
Harpreet
Apr 30 '08 #3
hsriat
1,654 Expert 1GB
Now what can be the problem with this.. If you have ever used swift mailer.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. require_once "lib/Swift.php";
  4. require_once "lib/Swift/Connection/SMTP.php";
  5.  
  6. $swift =& new Swift(new Swift_Connection_SMTP("mail.my_domain.com", 25));
  7.  
  8. $message =& new Swift_Message("Test Mail Subject", "Test Mail Message", "text/html");
  9.  
  10. if ($swift->send($message, "destination_address@yahoo.com", "my_address@my_domain.com"))
  11. {
  12.     echo "Message sent";
  13. }
  14. else
  15. {
  16.     echo "Message not sent";
  17. }
  18.  
  19. $swift->disconnect();
  20.  
  21. ?>
It shows "Message not sent" every time.
Jun 20 '08 #4
Atli
5,058 Expert 4TB
Are you using PHP4?
Swift uses Exceptions, which PHP4 does not support. If you were using PHP5, an exception should have been thrown, showing you what the problem is.

Try something like this. It should show you what is causing the error.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. Swift_Errors::expect($e, "Swift_ConnectionException");
  3. $result = $swift->send(...);
  4.  
  5. if(!$result) {
  6.   if($e != null) {
  7.     echo "Failed: ". $e->getMessage();
  8.   }
  9.   else  {
  10.     echo "Failed: Unknown error.";
  11.   }
  12. }
  13. else {
  14.   echo "Sucess!";
  15. }
  16. ?>
  17.  
Jun 20 '08 #5
hsriat
1,654 Expert 1GB
Fatal error: Class 'Swift_Errors' not found

I'm using PHP 5.
There is no class as Swift_Errors. There's a Swift_Exception class, but it contains no method.
Jun 21 '08 #6
Atli
5,058 Expert 4TB
No, Swift_Errors is specific to PHP4 only.
The PHP5 version throws exceptions so there is no need for it.

Try something like this.

Btw, if you are using PHP5, there is no need to pass new object by reference. PHP does it automatically.
Jun 21 '08 #7
hsriat
1,654 Expert 1GB
Now it always says "Not sent"
[PHP]<?php

require_once "swift/Swift.php";
require_once "swift/Swift/Connection/SMTP.php";

try
{
$swift =& new Swift(new Swift_Connection_SMTP("mail.my-domain.in"));

$message =& new Swift_Message("Test Mail Subject", "Test Mail Message", "text/html");

$is_Sent = $swift->send($message, "destination@yahoo.com", "no-reply@my-domain.in");

if ($is_Sent) echo "Sent";

else echo "Not sent";

}

catch (Swift_ConnectionException $e)
{
echo "There was a problem communicating with SMTP: " . $e->getMessage();
}

catch (Swift_Message_MimeException $e)
{
echo "There was an unexpected problem building the email:" . $e->getMessage();
}

$swift->disconnect();

?>[/PHP]
Jun 21 '08 #8
hsriat
1,654 Expert 1GB
Ok, I changed my mind and used PHP Mailer.
I sent a mail 4 hour ago to my yahoo address, and I just got it now.
Jun 21 '08 #9
Atli
5,058 Expert 4TB
Ok, I changed my mind and used PHP Mailer.
I sent a mail 4 hour ago to my yahoo address, and I just got it now.
That would probably be due to Yahoo's hyperactive spam filters.
I would guess that your mail was flagged and queued for some advanced filtering, which will probably take a while for a huge service like Yahoo.

But if the mail got there eventually, your mail script is working as it should.
Jun 21 '08 #10
Atli
5,058 Expert 4TB
Now it always says "Not sent"
That's very weird...

I was under the impression that Swift would throw exceptions if something, like sending, failed in PHP5.

According to that, you should never get the "Not sent" message, but rather the exception.

You didn't get any errors or warnings or anything like that?
Jun 21 '08 #11
hsriat
1,654 Expert 1GB
That's very weird...

I was under the impression that Swift would throw exceptions if something, like sending, failed in PHP5.

According to that, you should never get the "Not sent" message, but rather the exception.

You didn't get any errors or warnings or anything like that?
No error message, just 'not sent' thing.

But now I'm not working on that anymore. PHPMailer worked in the first try. So I'll stick to it.

And I understand that that 4 hours issue is not my script's problem but the intermediate servers' delay. Moreover my hosting server sux, I'll find another one at the end of this annual contract.

Thank you Atli :)

Harpreet
Jun 22 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
40
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
2
by: Ron | last post by:
hi guys, I am trying to send email using smtpMail. I can send emails inside the organization, but out of the organization I get an error "The server rejected one or more recipient addresses. The...
3
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
2
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import...
3
by: YMPN | last post by:
Hi Everyone, I'm deen from Riyadh. Please do help me with some problem i have. I have this formview control setup to recieved inputs from user (textbox, dropdownlist, others). After...
9
by: Mahernoz | last post by:
Can i send an email from JavaScript? Is it possible? If yes please the code to send email using javascript...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.