Solved

PHP Mail

Posted on 2013-06-20
7
708 Views
Last Modified: 2013-11-03
Hello,

I am trying this PHP code to send email. In an earlier attempt I was able to send mail properly but that was setting up PHP.ini setting.

In this attempt, I am trying to setup my smtp settings in the email program itself.

Attached is the new file.

Thanks,

San.
smtpmail.php
0
Comment
Question by:sanjay-gandhi
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:Averitteg
ID: 39263018
Are you getting any errors??  What is the issue?
0
 

Author Comment

by:sanjay-gandhi
ID: 39263158
Oh yes, I forgot to send the error I am facing:

Failed to set sender: noreply@kenhal.com [SMTP: Invalid response code received from server (code: 530, response: The SMTP server requires a secure connection or the client was not authenticated.(#5.7.1))]

Here is the problem.

- San.
0
 
LVL 2

Expert Comment

by:Averitteg
ID: 39263180
have you enabled ssl?

You have 'auth' => false, yet the server is requiring authentication.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:sanjay-gandhi
ID: 39263453
If I make it true, I get the following error: (I've tried various combinations, getting different errors, so I'll keep informing you about the errors). In fact, the pwd is N0Reply (case sensitive), so it may become easy for you. On the other hand, I am running Xampp, and the PHP.ini and sendmail.ini is also existing there as it is. Here is the error with Auth=True.

authentication failure [SMTP: Invalid response code received from server (code: 535, response: authorization failed (#5.7.0))]

I've not enabled SSL. It is none in my Outlook settings where this mail is working fine.

- San.
0
 

Accepted Solution

by:
sanjay-gandhi earned 0 total points
ID: 39610893
Finally this code works fine, sending mail from website using PHP.

<?php
 include_once("Mail.php");
 
 $from = $_POST["FlFirstName"]." <".$_POST["FlEmail"].">";
 $to = "Info <info@yourdomain.com>";
 $subject = "Visitor Mail From ".$_POST["FlFirstName"];
 $body = $_POST["FlDetails"]."\r\n"."\r\n";
 $body .= $_POST["FlFirstName"]." ".$_POST["FlLastName"].","."\r\n".$_POST["FlEmail"]."\r\n";
 $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 $body.= substr($url,7,14);
 
 $host = "webmail.yourdomain.biz";
 $username = "site@yourdomain.biz";
 $password = "1234yourpassword";
 
 $headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
 $smtp = @Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));
 
 $mail = @$smtp->send($to, $headers, $body);
 
 if (@PEAR::isError($mail))
   {
	   $message = "Your mail could NOT be submitted successfully, please send direct mail to...email@yourdomain.com";
   }
   else
   {
	   $message = "Your mail has been submitted successfully to...email@yourdomain.com";
   }
 echo "<script type='text/javascript'>alert('$message');</script>";
 echo "<script type='text/javascript'>history.back();</script>";
?>

Open in new window


Yes, you need to change Host, Username, Password in this code. And also use this PHP file as reference in your html code in 'action' in 'form' tag.

And the variables flEmail, flFirstName... are fields in html code, where in the form we accept user values in these fields. And then we transfer these fields to PHP file to process and send mail. These variables are used in Contact Us page in html file.

Thanks for support.

- San
0
 
LVL 2

Expert Comment

by:Averitteg
ID: 39611144
I see that you did enable the auth=true.  I'm glad that it worked out for you.
0
 

Author Closing Comment

by:sanjay-gandhi
ID: 39619723
Probably after lot of struggle, I could get the exact way I wanted this answer to work for my requirement. So after finding solution, I thought it was my duty to share the answer.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Group By Not Working on Query 3 25
only allow numbers with preg match 4 24
updating table data with inner join 9 24
using php variable inside javascript 5 11
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now