Advertisement

08.06.2008 at 05:40AM PDT, ID: 23625384 | Points: 500
[x]
Attachment Details

Using SwiftMailer

Asked by MarleneAyers in PHP Scripting Language

Attached is my Swiftmailer code. This is supposed to be a form letter on a php page that a user clicks, completes his first and last name and then  sends to a city council email address. I want the return and reply address to show as the users email address BUT In order for this to work, my isp says I have to use a return email that is a valid email name from my domain. I am not sure how to accomplish what I am after. I was going to use a simple mailto() link but after some research discovered that is not very reliable.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
<html>
<body>
 
<?php
 
$email_template = <<<THEEND
<div style="text-align:right">August 6, 2008</div>
 
<div style="text-align:left;">City Council Member<br>
275 E. Olive Avenue<br>
P.O. Box 6459<br>
Burbank, CA  91510<br>
 
Email:  options@frontex.com<br></div>
<p>Dear City Council Member,</p>
 
<p style="text-align:left;">I am writing in support of the Burbank Community YMCA.  I know there is a proposal pending 
asking the City Council to grant a loan to the YMCA to enable the purchase property on San Jose
Avenue.  This property would then be converted into additional parking spaces for the YMCA, 
alleviating the current parking shortfall and related safety issues.</p>
 
<p style="text-align:left;">I urge you to grant the Burbank Community YMCA's full request. Doing so would be in the best
interest of supporting the long term health of this organization and the Burbank Community YMCA.
Please vote "YES"" to grant this loan.</p>
 
<div style="text-align:right;">
Respectfully,<br>
{FIRST_NAME} {LAST_NAME}<br> 
Burbank Resident</div>
THEEND;
 
if (isset($_GET['support']))
{//echo the form
echo<<<THEEND
<form method="post" action="test.php?show_letter">
First name: <input type="text" name="first_name"><br>
Last name: <input type="text" name="last_name"><br>
<input type="submit" value="Submit">
</form>
 
THEEND;
}
elseif (isset($_GET['show_letter']))
{//show filled letter
        $first_name = (isset($_POST['first_name']))?$_POST['first_name']:"";
        $last_name = (isset($_POST['last_name']))?$_POST['last_name']:"";
        if (empty($first_name)||empty($last_name))
        {
                echo "Sorry, no anonymous support needed.";
        }
        else
        {
                $email = str_replace('{FIRST_NAME}',$first_name,$email_template);
                $email = str_replace('{LAST_NAME}',$last_name,$email);
                echo "Your email:<br><div style=\"border: solid 1px black;padding:10px;\">$email</div>";
                echo <<<THEEND
                <form method="post" action="test.php?send_letter">
		
                <input type="hidden" name="first_name" value="$first_name">
                <input type="hidden" name="last_name" value="$last_name">
                <input type="submit" value="Send letter">
                </form>
                <form method="post" action="test.php?cancel">
                        <input type="submit" value="Cancel">
                </form>
THEEND;
        }
}
elseif  (isset($_GET['send_letter']))
{
        $first_name = (isset($_POST['first_name']))?$_POST['first_name']:"";
        $last_name = (isset($_POST['last_name']))?$_POST['last_name']:"";
        if (empty($first_name)||empty($last_name))
        {
                echo "Sorry, no anonymous support needed.";
        }
        else
        {
                $email = str_replace('{FIRST_NAME}',$first_name,'<html><body>'.$email_template.'</body><html>');
                $email = str_replace('{LAST_NAME}',$last_name,$email);
                $subject = "YMCA Support";
                $smtp_server = "mail.mywebsite.com";
                $smtp_user = "myusername";
                $smtp_pass = "mypassword";
             
                require_once "lib/Swift.php";
                require_once "lib/Swift/Connection/SMTP.php";
                $smtp =& new Swift_Connection_SMTP($smtp_server);
                $smtp->setUsername($smtp_user);
                $smtp->setPassword($smtp_pass);
                $swift =& new Swift($smtp);
 
                $message =& new Swift_Message($subject, $email, "text/html");
                $recipients =& new Swift_RecipientList();
                $recipients->addTo("recipientName", "City Council Member");
                
                
 
                if ($swift->send($message, $recipients, "what goes here?"))
                {
                echo "Message sent";
                }
                else
                {
                echo "Message failed to send. Try again later.";
                }
                $swift->disconnect();
        }
}
else //show link
{
        echo '<a href="test.php?support">Show support</a>';
 
}
?>
 
</body>
</html>
 
Loading Advertisement...
 
[+][-]08.06.2008 at 02:13PM PDT, ID: 22175205

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628