Basic example for sending an email please.

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
geddi
Forum Commoner
Posts: 39
Joined: Sun Feb 24, 2008 11:01 am

Basic example for sending an email please.

Post by geddi »

Hello,

I have read the docs and I as am new to this and maybe a
bit dumb, I could not really follow how to send the email out.

From the docs I have got this far:

Code: Select all

/* 
*       b_email_act.php
*
*
*  send WAITING CONFIRMATION email  
*/     
   
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
 
//Create the message
$message =& new Swift_Message("My subject", "My body");
 
//Now check if Swift actually sends it
if ($swift->send(
    $message, new Swift_Address("recipient@address.tld", "Recipient Name"),
    new Swift_Address("sender@address.tld", "My Name")){
        echo "Sent to $sent recipients";
        }
else{
   echo "Failed";
     }  // end else
 
 
I hope its is correct.

But what I don't get is how my message fits in :(

I need to send a confirmation email - so it has to contain a link:

So this is my message:

Code: Select all

 
<html>
<head>
<title>Yodbod.com the Free Ads site</title>
</head>
<body>
<div style = ' 
  width:600px; 
  background-color:white; 
    font-family:Tahoma, Tunga, sans-serif;
    font-size:14;
    text-align:left; 
    font-weight:normal;
    padding:1px;
  margin:1px;
 '>
<p>
<br>
<center><b>Waiting for confirmation on your first advert.</b></center>
<br><br>
Dear $N_contact,
<br><br>
For your security we require that you confirm the advertisement placement by clicking on the 
link below. By confirming your advertisement you also confirm your agreement to the terms of use 
as set out in the terms.php document.
<br><br>
Please activate your advertisement NOW.<br><br>
ACTIVATE: <a href=\"http://www.yodbod.com/activate.php?client=$N_email\">Activate my Advert.</a>
<br><br>
Your email and password are recorderd as follows:<br>
Email: $N_email <br>
Password : $N_pass<br>
<br>
Thanks.<br>
</p>
</div>
</body>
</html>
";
The subject would be "Confirm your free advert".

Would appreciate any help.

Thanks
chetan1
Forum Newbie
Posts: 6
Joined: Mon May 05, 2008 2:14 am

Re: Basic example for sending an email please.

Post by chetan1 »

If u write this code.It would not be wrong and u don't mention here any error which u face.Keep it up and execute it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Basic example for sending an email please.

Post by Chris Corbyn »

Hint, the "My body" in the first chunk of code you posted *is* the message.
Post Reply