/    Sign up×
Community /Pin to ProfileBookmark

It worked! Kind of…

Ok, well a few days ago I put a post asking for help with a form to send the data via e-mail. Well, I finally figured out what I was doing wrong, I think I just had some typo’s and names didn’t match. Anyway, the script worked and didn’t give me any errors. However, even though the script worked I still have not received any e-mails with the contents of the form on any of my e-mail accounts I told it to send it to. I pretty much set up the script to send an e-mail to all my different accounts so that I could confirm that it really worked. Well, like I said, I am not getting the actual e-mail from the script. Does anyone know how to correctly configure php.ini in windows so that I know the smtp server settings are correct. I tried using the smtp server of my ISP but it requires authentication for all outgoing mail as well as incoming mail. So, I tried a different ISP smtp server (which I happen to know because I used to use them) and I know that their smtp server does not require an outgoing authentication, but I still am not getting e-mails. I put a e-mail address to use for sending but I am not sure if there has to be anything special about the sent from address either. Can anyone offer some help with figuring this out?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@coppocksDec 18.2006 — You might want to take a look at this, it allows additional settings for your SMTP that php mail does not... I've not used it, but it may be the answer you need for Windows usage...

http://phpmailer.sourceforge.net/
Copy linkTweet thisAlerts:
@polorboyauthorDec 18.2006 — Looks interesting, I will see if it helps any. Thanks.
Copy linkTweet thisAlerts:
@polorboyauthorDec 19.2006 — Ok, here is the revised code using phpmailer addon.

[code=php]
<?php
require("class.phpmailer.php");

$userName = $_POST['userName'];
$userEmail = $_POST['userEmail'];
$userMessage = $_POST['userMessage'];

$mail = new PHPMailer();

$mail->IsSMTP(); //Set SMTP Mailer
$mail->Host = "smtp.domain.com"; //Sets up the SMTP servers to use
$mail->SMTPAuth = true; //Turn on SMTP Authentication
$mail->Username = "[email protected]"; //SMTP User Name
$mail->Password = "password goes here"; //SMTP Password

$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML


function empMail($userName, $userEmail, $userMessage){
$mail->From = $userEmail;
$mail->FromName = $userName;
$mail->Subject = "File Upload Notification";
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddReplyTo($userEmail);
$mail->Body = $userName.' <'.$userEmail.'> has uploaded a file with the following message:' . "<br/>" .$userMessage;
}

function userMail($userName, $userEmail, $userMessage){
$mail->Subject = "File Upload Notification";
$mail->From = "[email protected]";
$mail->FromName = "Employee Name";
$mail->AddAddress($userEmail);
$mail->AddReplyTo("[email protected]","Employee Name");
$mail->Body = 'Your file was successfully uploaded and your message delivered. Below is the contents of your message:' . "<br/>" .'Your information: '.$userName. '<'.$userEmail.'>' . "<br/>" .'Your message: '.$userMessage;
}

//send email to user and employees if form was submitted correctly
if ($mail->Send()){
if (strlen($userName) && strlen($userEmail) && strlen($userMessage)){
userMail($userName, $userEmail, $userMessage);
empMail($userName, $userEmail, $userMessage);
print("<p>Your information was sent successfuly. Here is what you sent:"."</p>");
print("<p>User Name: ".$userName."</p>");
print("<p>E-Mail Address: ".$userEmail."</p>");
print("<p>Your Message: ".$userMessage."</p>");
}
}
else {
print "You Must fill in all fields.";
}
?>
[/code]


Is anyone familiar with this addon? I tried the demo of it and it worked fine, but I need it to be able to take input from a form and send it back to the user and several other people. I changed the if statement at the end, so that if it can send it then do it, otherwise print that the user needs to fill in all the fields. So, instead of checking if it was not sent, i am checking if it was sent.
Copy linkTweet thisAlerts:
@polorboyauthorDec 19.2006 — Well, if anyone is hanging by a thread to see if i actually got this to work, I did. I realized that you can't put the phpmailer variables in a function (or at least I don't know enough about php yet to be able to do that and get it to work). I removed the function definitions and added a $mail->AddAddress(); for each e-mail I wanted to send to and.. well here take a look:

[code=php]
<?php
require("class.phpmailer.php");

$userName = $_POST['userName'];
$userEmail = $_POST['userEmail'];
$userMessage = $_POST['userMessage'];

$mail = new PHPMailer();

$mail->IsSMTP(); //Set SMTP Mailer
$mail->Host = "smtp.domain.com"; //Sets up the SMTP servers to use
$mail->SMTPAuth = true; //Turn on SMTP Authentication
$mail->Username = "Username for SMTP"; //SMTP User Name
$mail->Password = "Password"; //SMTP Password

$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML


$mail->From = $userEmail;
$mail->FromName = $userName;
$mail->Subject = "Employee File Upload Notification";
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddReplyTo($userEmail);
$mail->Body = $userName.' <'.$userEmail.'> has uploaded a file with the following message:' . "<br/>" .$userMessage;

//send email to user and employees if form was submitted correctly
if (strlen($userName) && strlen($userEmail) && strlen($userMessage)){
if(!$mail->Send()) {
print "You're E-Mail could not be sent.<br/>";
print "There was a problem with your email.";
}
else {
print("<p>Your information was sent successfuly. Here is what you sent:"."</p>");
print("<p>User Name: ".$userName."</p>");
print("<p>E-Mail Address: ".$userEmail."</p>");
print("<p>Your Message: ".$userMessage."</p>");
}
}
else {
print "You're E-Mail could not be sent.<br/>";
print "Please fill in all the fields.";
}
?>
[/code]


That along with a form was able to successfully send me an e-mail. Of course I used real e-mails and a real smtp server in my script, but I removed them from what I am posting.
×

Success!

Help @polorboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...