473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Problems sending email via smtp

I'm trying to setup a Form and send it to our helpdesk so that we don't have to email forms all day long. The problem is that I have very little knowledge of PHP and I cannot seem to find the same thing that I am tring to do on the internet so I can compare what exactly is going wrong. Here is my code(leaving a lot of html out to save space):
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
$me = $_SERVER['PHP_SELF'];
?>
</div>
<form method="post" name="form1" id="form1" action="<?=$me?>">
<div align="center">
<?
$name = $_POST["name"];
$position = $_POST["position"];
$location = $_POST["location"];
$department = $_POST["department"];
$user_phone = $_POST["user_phone"];
$user_email = $_POST["user_email"];
$manager = $_POST["manager"];
$manager_phone = $_POST["manager_phone"];
$manager_email = $_POST["manager_email"];
$time_zone = $_POST["time_zone"];
$start_date = $_POST["start_date"];
$printer = $_POST["printer"];
$request_type = $_POST["request_type"];
$access_type = $_POST["access_type"];
$model_after_user1 = $_POST["model_after_user1"];
$model_after_1 = $_POST["model_after_1"];
$model_after_user2 = $_POST["model_after_user2"];
$model_after_2 = $_POST["model_after_2"];
$notes = $_POST["notes"];
?>
(htmlcodehere)
</form>
<?php
} else {
error_reporting(0);
$errors = array();
if (!$_POST['name'])
$errors[] = "Name is required";
if (count($errors)>0) {
foreach($errors as $err)
echo "$err<br>\n";
echo "<br>Please use your browser's Back button to fix.";
} else {
$recipient = 'aerosmith_freak_03@yahoo.com';
$from = stripslashes($_POST['name']);
$subject = "User Request";
$msg = "Message sent by $from\n";
$msg.="\nName: ".$_POST['name'];
$msg.="\nPosition: ".$_POST['position'];
$msg.="\nLocation: ".$_POST['location'];
$msg.="\nDepartment: ".$_POST['department'];
$msg.="\nUser's Phone: ".$_POST['users_phone'];
$msg.="\nUser's E-mail: ".$_POST['users_email'];
$msg.="\nManager: ".$_POST['manager'];
$msg.="\nManager's Phone: ".$_POST['managers_phone'];
$msg.="\nManager's Email: ".$_POST['managers_email'];
$msg.="\nTime Zone: ".$_POST['time_zone'];
$msg.="\nStart Date: ".$_POST['start_date'];
$msg.="\nPrinter: ".$_POST['printer'];
$msg.="\nRequest Type: ".$_POST['request_type'];
$msg.="\nPosition: ".$_POST['position'];
$msg.="\nAccess Type: ".$_POST['access_type'];
$msg.="\nModel After User1: ".$_POST['model_after_user1'];
$msg.="\nModel After 1: ".$_POST['model_after_1'];
$msg.="\nModel After User2: ".$_POST['model_after_user2'];
$msg.="\nModel After 2: ".$_POST['model_after_2'];
$msg.="\nNotes: ".$_POST['notes'];
$msg.="\nColor: ".$_POST['color'];
if (mail($recipient,$subject,$msg)){
echo "<p>Your request has been sent</p>";
echo nl2br($msg);
} else
echo "";
}
}
?>
</body>
</html>
If this matters, model_after_1, model_after_2, and access_type come from checkbox groups. location and time_zone come from drop down menus. request_type is a radio button group. The rest come from text boxes.
Thanks
Mar 16 '07 #1
6 2772
ak1dnar
1,584 Expert 1GB
what is the Error here you are getting.
in your mail() function some headers missing.
Please use [PHP] tags around your coding next time, its hard to read.
Mar 17 '07 #2
Well, that's part of the problem, when I submit the form I don't recieve any errors. The page refreshes like it sent something but I never recieve an email or any real indication that it did something. I added "error_reporting(E_ALL);" to see if that would tell me anything and I get nothing but "Notice: Undefined index: name in F:\intranet\php\index.php on line 27" thru to the "notes" variable. I can send you the whole page if you would like, I just couldn't post it all here Here is a link to it http://docs.google.com/Doc?id=d773v34_0g28tv6
Thanks, Brad
Mar 19 '07 #3
ak1dnar
1,584 Expert 1GB
First of all we'll check whether this one is working or not. change $to variable here in to your email (gmail/yahoo). if you got the "Mail Sent." message then we'll try to fix the original coding.

Check Your Spam box if the mail is not there in your mail inbox.

[PHP]<?php

$to = "your_Mail_id_@gmail.com";//Change this to your Mail Address
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "some1@gmail.com";
$headers = "From: $from";
if(mail($to,$subject,$message,$headers))
{
echo "Mail Sent.";
}else{
echo "Error Occured";
}
?>[/PHP]

if this one is working in your host, send me the HTML form and PHP script to the this forum.
if this one is not working the problem is in your SMTP settings.
Where did you test the application localhost or ??
Mar 19 '07 #4
This didn't work, here is the error I got: "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in F:\intranet\php\test.php on line 14" [if(mail($to,$subject,$message,$headers))] I have set the php.ini file to point to our mail server (different location) and use the correct ports. This I know is right, I don't agree with this but I was told that I didn't need to specify a username and password for the mail server. I have to specify one when I log on, why wouldn't I have to for this? If that is the problem then where do I specify a username and password?
Mar 19 '07 #5
I found my problem, I thought setting the smtp server in the php.ini file was enough. Apparently not, I added ini_set "("SMTP","XXX.XXX.com");
ini_set("sendmail_from","php@XXX.com");" and that got it. Thanks, without knowing where to start on this one it would have taken me forever to find out what was going on.
Mar 19 '07 #6
ak1dnar
1,584 Expert 1GB
I found my problem, I thought setting the smtp server in the php.ini file was enough. Apparently not, I added ini_set "("SMTP","XXX.XXX.com");
ini_set("sendmail_from","php@XXX.com");" and that got it. Thanks, without knowing where to start on this one it would have taken me forever to find out what was going on.
If you configured your php.ini file correctly again no need to go for ini_set().
I did not mentioned your O/S, this is for Windows.
by default there is a ";" of each and every line. that means php.ini file will ignore this line.so we have to remove that.

Eg:
Expand|Select|Wrap|Line Numbers
  1. ;smtp_port = 25
Settings:
Expand|Select|Wrap|Line Numbers
  1. [mail function]
  2. ; For Win32 only.
  3. SMTP = smtp_or_mail.your_ISP.com 
  4. smtp_port = 25
This is the default from Address, but we can change it from mail() function.

Expand|Select|Wrap|Line Numbers
  1. ; For Win32 only.
  2. sendmail_from = whatever@your_ISP.com
Mar 20 '07 #7

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

Similar topics

13
by: joe215 | last post by:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using...
1
by: Srinivas | last post by:
Hi, I am using ASP.NET SmtpMail to send email using the following code public void SendEmail(string From, string To, string Subject, StringBuilder Message, string Attachment, string...
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
3
by: armando perez | last post by:
Hi, this is my first time here, but I was looking for something that may help me, and still, I haven't found something to use. I'm using a website made in .NET with C#, when I'm running my site...
8
by: Mike Owen | last post by:
Hi, I am using the following code to send email on a Windows 2003 Web Server: Imports System.Net.Mail ........ Dim msgmail As New MailMessage msgmail.To.Add(New...
2
by: oliu321 | last post by:
Hi, First I am not trying to write a client to talk with hotmail straightly. I am trying to write some codes to send emails through a SMTP server. I wrote a C++ version using pure socket...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
6
by: Jack | last post by:
Hi, I am still new to .NET so, i'm sorry if my question is a bit too simple :-) I would like to know what is the "best-practice-way" of sending email from asp.net (VbScript). I want to make a...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
0
BarryA
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...
0
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...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...

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.