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
11 2633 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.
Thank you for the links.
They are really helpful.
:)
Regards,
Harpreet
Now what can be the problem with this.. If you have ever used swift mailer. - <?php
-
-
require_once "lib/Swift.php";
-
require_once "lib/Swift/Connection/SMTP.php";
-
-
$swift =& new Swift(new Swift_Connection_SMTP("mail.my_domain.com", 25));
-
-
$message =& new Swift_Message("Test Mail Subject", "Test Mail Message", "text/html");
-
-
if ($swift->send($message, "destination_address@yahoo.com", "my_address@my_domain.com"))
-
{
-
echo "Message sent";
-
}
-
else
-
{
-
echo "Message not sent";
-
}
-
-
$swift->disconnect();
-
-
?>
It shows "Message not sent" every time.
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. -
<?php
-
Swift_Errors::expect($e, "Swift_ConnectionException");
-
$result = $swift->send(...);
-
-
if(!$result) {
-
if($e != null) {
-
echo "Failed: ". $e->getMessage();
-
}
-
else {
-
echo "Failed: Unknown error.";
-
}
-
}
-
else {
-
echo "Sucess!";
-
}
-
?>
-
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.
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.
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]
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.
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.
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |