473,624 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending E-mails through MySql

16 New Member
I have a table where i enter the students details.
Whenever we insert a row in this table, a mail should be sent to the student for the student to verify the details entered.
The email id is already stored in the table.
How to implement this using mysql?

Expand|Select|Wrap|Line Numbers
  1. create table s_details(
  2.     SELECT_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  3.     REF_NUMBER VARCHAR(20),
  4.     REG_NO VARCHAR(20),
  5.     TITLE    varchar(4) NOT NULL,        
  6.     FIRST_NAME    varchar(30) NOT NULL,
  7.     MIDDLE_NAME    varchar(30),
  8.     LAST_NAME    varchar(30) NOT NULL,
  9.     DATE_OF_BIRTH    date NOT NULL,
  10.     NATIONALITY    varchar(50) ,
  11.     E_MAIL        varchar(80) NOT NULL,
  12.     DAY_NUMBER    int NOT NULL,
  13.  
  14.     )TYPE=innodb;
  15.  
This is the table...
pls can anyone help on this?
Oct 22 '07 #1
15 81793
ronverdonk
4,258 Recognized Expert Specialist
Email is sent via the server language used to insert the table (such as PHP), not by MySQL.
Since you have the email details at the time you insert the new row, you can easily construct an email message and sent it from your insert-into-MySQL script.

Ronald
Oct 22 '07 #2
praveena mani
16 New Member
Email is sent via the server language used to insert the table (such as PHP), not by MySQL.
Since you have the email details at the time you insert the new row, you can easily construct an email message and sent it from your insert-into-MySQL script.

Ronald
Can u provide me more details on this!!
Oct 23 '07 #3
JamieHowarth0
533 Recognized Expert Contributor
Hi praveena,

There are two ways of doing what you are asking for.

The first way is programatically - i.e. you have a section on your website where the user puts in their details and signs up. This sign-up script saves the user's information into the database using PHP, ASP or whatever server-side language you are using.
What ronverdonk is suggesting is adding a few extra bits of code into this sign-up script that automatically sends the email to the new user (which makes sense unless you are planning on adding users manually to your database using a back-end application).

The other way is by using MySQL's SELECT... INTO OUTFILE functionality.
I recently created my own user database and wanted to send automated emails to them when they signed up to verify their email address.
I worked out a trigger that:
  1. Captured the new user's details (email, name and new Unique ID to verify email);
  2. Retrieved an HTML template from a table in my database;
  3. Substituted the user's details into that template;
  4. Outputted the resulting HTML as a ".eml" file into my mail server's pickup folder, using INTO OUTFILE SQL, and it got sent automatically!
I will put up my trigger code a little later on as I don't have it to hand at present, but I hope that this helps towards your problem.

Best regards,

medicineworker
Oct 23 '07 #4
fbachofner
3 New Member
Any chance you can post this code?

I am working on something similar.


Thanks.
Feb 16 '08 #5
JamieHowarth0
533 Recognized Expert Contributor
Finally found the code in my code-bank!

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER send_emailverifier AFTER INSERT, UPDATE ON tbl_users
  2. FOR EACH ROW BEGIN
  3. SELECT * FROM email_bodies WHERE EmailID = 1;
  4. SELECT * FROM tbl_users WHERE ClientID = @ClientID
  5. INSERT INTO tbl_emailverify VALUES (UUID, tbl_users.ClientID, OLD.CltEmail, NEW.CltEmail)
  6. SELECT concat("To: ",NEW.CltEmail & "," & OLD.CltEmail),
  7.                 "From: triggers@yourmysqlserver.whatever",
  8.                 concat("Subject: ",NEW.subject),
  9.                 "",
  10.                 email_bodies.EmailContent
  11. INTO OUTFILE "/inetpub/mailroot/pickup/mail.eml"
  12. FIELDS TERMINATED BY '\r\n';
  13. END
  14.  
I will be altering this function to accommodate more name-value substitutions into the email body as well as turning it into a stored procedure instead of a single trigger - that way it has far more benefit across a DB deployment.

medicineworker
Feb 17 '08 #6
CodeMaster123
4 New Member
If you are using PHP as a server side scripting language use mail function of PHP to send an e-mail
Expand|Select|Wrap|Line Numbers
  1. syntax:
  2. bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )
  3.  
  4. example:
  5. <?php
  6.  
  7. $body_of_mail = "Line 1\nLine 2\nLine 3";
  8. $receivers_email_id="xyz@abc.com";
  9. $subject="mail";
  10. mail($body, $subject, $message);
  11.  
  12. ?>
Feb 18 '08 #7
ronverdonk
4,258 Recognized Expert Specialist
If you are using PHP as a server side scripting language use mail function of PHP to send an e-mail

syntax:
bool mail ( string to, string subject, string message [, string additional_head ers [, string additional_para meters]] )

example:
<?php

$body_of_mail = "Line 1\nLine 2\nLine 3";
$receivers_emai l_id="xyz@abc.c om";
$subject="mail" ;
mail($body, $subject, $message);

?>
Ok, but how do you propose to accomplish that via the MySQL TRIGGER? Show us that code please.

Ronald
Feb 18 '08 #8
nityaprashant
19 New Member
May be this help ful to u...
Expand|Select|Wrap|Line Numbers
  1.  Dim msg As EnhancedMailMessage = New EnhancedMailMessage
  2.   msg.From = "xt@x.com" '"invoice@x.com" 
  3.                 msg.FromName = "Administraor"
  4.                 msg.To = "nitya@x.com"
  5.                 msg.Subject = "Order with [" + transid + "]: "
  6.                 msg.Body = lblmail.Text + lblmsg.Text
  7.                 msg.BodyFormat = MailFormat.Html
  8.                 msg.SMTPServerName = "mail.x.com" '"mail.x.com"
  9.                 msg.SMTPUserName = "x@x.com" '"invoice@x.com"
  10.                 msg.SMTPUserPassword = "xxxx" 
  11.                 msg.SMTPServerPort = 25
  12.                msg.Send()
Feb 18 '08 #9
ronverdonk
4,258 Recognized Expert Specialist
May be this help ful to u...

Dim msg As EnhancedMailMes sage = New EnhancedMailMes sage
msg.From = "xt@x.com" '"invoice@x.com "
msg.FromName = "Administra or"
msg.To = "nitya@x.co m"
msg.Subject = "Order with [" + transid + "]: "
msg.Body = lblmail.Text + lblmsg.Text
msg.BodyFormat = MailFormat.Html
msg.SMTPServerN ame = "mail.x.com " '"mail.x.com "
msg.SMTPUserNam e = "x@x.com" '"invoice@x.com "
msg.SMTPUserPas sword = "xxxx"
msg.SMTPServerP ort = 25
msg.Send()
Annh how do you trigger that from MySQL using the TRIGGER function?

Ronald
Feb 18 '08 #10

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

Similar topics

1
14508
by: coder_1024 | last post by:
I'm trying to send a packet of binary data to a UDP server. If I send a text string, it works fine. If I attempt to send binary data, it sends a UDP packet with 0 bytes of data (just the headers). I can see this because I'm running Ethereal and watching the packets. I'm defining the packets as shown below: $text_msg = "Hello, world\r\n"; $binary_msg = chr(0x01).chr(0x02).chr(0x03).chr(0x00).chr(0xA0); $binary_msg_size = 5;
0
522
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils import mimetypes import os,string
3
4623
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
4
8196
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with TcpClient, NetworkStream and StreamWriter classes. but with low level socket it doesn't work (When using the Socket class Send method).
3
3609
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is smtpMail.Send("from@here.com", to@there.com, "Message subject", "Message Body") I'm sending it to my own email address on a different server using a dummy
3
7719
by: Sydney | last post by:
Hi, I am trying to construct a WSE 2.0 security SOAP request in VBScript on an HTML page to send off to a webservice. I think I've almost got it but I'm having an issue generating the nonce value for the UserName token. Is it possilbe at all to do this from VBScript (or jscript?)? I know I will be limited with what I can do with the SOAP message. Eg/ can't sign/encrypt it etc. Thanks,
0
1855
by: remya1000 | last post by:
by using FTP i can send files to server using vb.net. if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by one,then whethere we can show the progress of each file sending to server in progress bar. so that the FTP clients can see the progress of file sending to the server. any idea how we can do this to show the progress of each file sending. if we...
9
3452
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
4
2394
by: =?Utf-8?B?R3V5IENvaGVu?= | last post by:
Hi all I use: Dim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text) Dim emailClient As New SmtpClient(txtSMTPServer.Text) emailClient.Send(message) And its working fine. However I was wondering if there is a way to confirm that the email was sent. The send method does not return anything....
6
9201
by: Chocolade | last post by:
Hi, Im using System.Net.Mail to send email in my application it was working great without any problems untill this morning after like 20-30 tries it was sending the email ok then suddenly this morning i got an exception and i cant figure out what/where the problem is and how to fix it. The problem say i have some invalid char: invalid character was found in the mail header: 'י'. Now this char 'י' is an hebrew letter. But i searched...
0
8238
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8478
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7164
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1485
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.