email confirmation on signup in php while using local host as aserver - php

i am new to php and web development. i am trying to confirm user,s email on signup by sending confirmation message on their email. But it is not working is the problem with my using localhost as a server or there is some other problem? here is my code
{
$to = $_POST['email'];
$com_code = md5(uniqid(rand()));
$subject = "Confirmation from OnlineShopping to $_POST['username']";
$header = "OnlineShopping: Confirmation from OnlineShopping";
$message = "Please click the link below to verify and activate your account. rn";
$message .= "http://www.yourname.com/confirm.php?passkey=$com_code";
$sentmail = mail($to,$subject,$message,$header);
if($sentmail)
{
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else
{
echo "Cannot send Confirmation link to your e-mail address";
}
}
my if($sentmail) condition is coming true and i am getting message that your confirmation link has been sent to your email address but i am not receiving any email in my inbox

Nowadays, ISPs usually block any smtp activity, you need a proper mail server. Easiest is to use the gmail smtp server to send mail, just to get you going.
There are plenty of ways to do that, just search "gmail smtp php" and you'll get a bunch of articles.

You need a host to send email with php. I recomend you to use .tk For a free domain and hostinger for free hosting. So you can use this function and test your stuff.
But you can also try changing the php.ini file. http://www.php.net/manual/en/mail.configuration.php

Related

when i am sending email from my php code through a 3rd party mail server, where do i save my emails?

i am using php code to send emails to gmail or yahoo ids. i am using a 3rd party mail server to send my emails. my php code works and i can receive the content in my gmail inbox. but where do i save my sent emails ?? who gives me an inbox for all my received / sent emails. suggest me a Name ?
function helloEmail()
{
$from = new Email(null, "test#example.com");
$subject = "Hello World from the SendGrid PHP Library";
$to = new Email(null, "test#example.com");
$content = new Content("text/plain", "some text here");
$mail = new Mail($from, $subject, $to, $content);
$to = new Email(null, "test2#example.com");
$mail->personalization[0]->addTo($to);
//echo json_encode($mail, JSON_PRETTY_PRINT), "\n";
return $mail;
}
There is no inbox for your sent mails. You can send an e-mail using any e-mail address you choose, even if it belongs to someone else or doesn't exist.
For your received e-mail inbox, you'll have to make one yourself via any third party e-mail service such as Gmail or Hotmail, or via your web hosting platform using your own domain name if they provide e-mail services.
To save your sent e-mails you can opt to save them in a database.

mailto function is not working with gmail address

How to send email from wamp/xampp localhost?
I have written the following simple code to send message.
I have already edited php.ini,sendmail.ini configuration files but no use,I can't receive email.I want to send message to any gmail address.I can sent email to my domain mail when this piece of code is uploaded via filezilla to my domain, but when I am giving to address as any gmail id, the code is not working.
<?php
$to = "bytecookiestest#gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: swetha851991#gmail.com";
$s=mail($to,$subject,$txt,$headers);
if($s)
echo "success";
else
echo "failure";
?>
It's most likely a problem with the from-header you're sending. You're using your own Gmail-address to send mails from, but that also means you have to use the Google SMTP server. The credentials of swetha851991#gmail.com are the credentials you have to use to authenticate with the SMTP server. It'll otherwise be marked as spam.
Another option is to set the from-address to an address from the domain you're sending it from. If you domain is example.com, you can set the from-address to anything#example.com.

cant send mail through contact form in yahoo small business server. Do i need any configurations done before the program like smtp?

I want to host the form in yahoo small business server. Do I have to configure anything else other then coding in the hosting? New to the webhosting.
i know the program works good but it shows error because i think there is no proper connection.
please to help.
send_contact.php
<?php
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
Yahoo requires you to do some setting up before you can send mail via PHP. All of the steps are detailed here:
https://help.yahoo.com/kb/yahoo-web-hosting/SLN20671.html?impressions=true

Submit Button Not Processing PHP form

http://www.bridgetjoy.com/Web/requestInfo.html
I am having trouble getting the above form to process...here is my php processing code, I am getting it to redirect to my success page but it is not showing up in my inbox. Any help would be appreciated. Thanks!
<?php
if(isset($_POST['submit'])) {
$to = "bridgetjoymedia#gmail.com" ; //put your email address on which you want to receive the information
$subject = "Information Request"; //set the subject of email.
$headers = "From: $email";
$message = "<table><tr><td>Title :</td><td>".$_POST['title']."</td></tr>
<tr><td>First Name :</td><td>".$_POST['firstName']."</td></tr>
<tr><td>Last Name :</td><td>".$_POST['lastName']."</td></tr>
<tr><td>Degree :</td><td>".$_POST['degree']."</td></tr>
<tr><td>Address :</td><td>".$_POST['address1']."</td></tr>
<tr><td> </td><td>".$_POST['address2']."</td></tr>
<tr><td> </td><td>".$_POST['address3']."</td></tr>
<tr><td>City :</td><td>".$_POST['city']."</td></tr>
<tr><td>State :</td><td>".$_POST['state']."</td></tr>
<tr><td>ZipCode :</td><td>".$_POST['zipCode']."</td></tr>
<tr><td>Country :</td><td>".$_POST['country']."</td></tr>
<tr><td>E-mail Address :</td><td>".$_POST['email']."</td></tr>
<tr><td> Secondary E-mail Address :</td><td>".$_POST['email2']."</td></tr>
<tr><td>Primary Phone :</td><td>".$_POST['phone1']."</td></tr>
<tr><td>Primary Phone Location :</td><td>".$_POST['phone1_location']."</td></tr>
<tr><td>Secondary Phone :</td><td>".$_POST['phone2']."</td></tr>
<tr><td>Secondary Phone Location :</td><td>".$_POST['phone2_location']."</td></tr>
<tr><td>Fax :</td><td>".$_POST['phone3']."</td></tr>
<tr><td>Reason for Request :</td><td>".$_POST['relation']."</td></tr>
<tr><td>Reason for Request :</td><td>".$_POST['relation_specify']."</td>
<tr><td>Reason for Request :</td><td>".$_POST['physician_specialty']."</td>
<tr><td>Reason for Request :</td><td>".$_POST['surgeon_specialty']."</td>
<tr><td>Reason for Request :</td><td>".$_POST['prof_specify']."</td></tr>
<tr><td>Reason for Request :</td><td>".$_POST['other_specify']."</td></tr>
<tr><td>Diagnosis :</td><td>".$_POST['diagnosis']."</td></tr>
<tr><td>Insurance :</td><td>".$_POST['insurance']."</td></tr>
<tr><td>How did you hear of Avery Biomedical :</td><td>".$_POST['source']."</td></tr>
<tr><td>Comments :</td><td>".$_POST['comments']."</td></tr>
</table>" ;
$send_contact = mail($to,$subject, $headers,$message);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
header("Location: success.html");
exit();}
else {
header("Location: failure.html");
exit();}
}
?>
Emails sent by mail() function is blocked due is used by scammers try to use sendmail from PEAR or a smtp class
phpmailer https://code.google.com/a/apache-extras.org/p/phpmailer/
PEAR sendmail https://pear.php.net/manual/en/package.mail.mail.send.php
Look at PHP: mail() vs SendMail
Many mail services, such as Gmail, vigorously check for spam, and much of the spam you would otherwise receive simply bounces, rather than even making it to your spam folder!
To prevent this, it helps if the mail server you are sending from has valid MX and SPF records, although this is fairly technical for most people. However, because Gmail is fairly well known, many services do not bounce email origination from smtp.mail.google.com (Gmail). Therefore, you might benefit from setting up an account for your script to use on Gmail, and then using a third-party library to connect to the account and send/receive emails.
If you haven't looked into it, SwiftMailer allows you to send mail on behalf of a Gmail account using PHP.

PHP e-mail to spam

I'm trying to email new registered users for email verification (PHP) but i don't get it, why would an email be sent to SPAM, i already checked out similar questions and all answers are about Headers,
It seems a bit complicated for me to get known to those headers and how are they being verified,
By sender website ? lets say i sent as user#google.com and the actual server domain is domain.com, how would it know? and is it one of the main reasons why it goes to spam ?
I am using VPS, does it has anything to do with it ?
I'm just trying to understand the clear/simple reasons of why would an email be checked as spam
and what if i sent from the server IP and not the domain itself
Most of the mail servers will do Reverse DNS lookup to prevent people from domain.com pretending to be from otherdomain.com. It will check if the IP address from which the email was sent resolves to the same domain name of the email sender. Yahoo and other big companies will also use DKIM to verify you.
Often your message can end up in Bulk/Spam if it doesn't have much content, or if you sent a lot of the same content to one server.
Here's a good article about what web developers should know about sending email that might help you understand the subject.
1) Check headers. You could use any email sending library such as PHPMailer (http://code.google.com/a/apache-extras.org/p/phpmailer/wiki/PHPMailer#Documentation_and_Resources)
2) Check hosting server. If your is using shared hosting then most probably it has been blacklisted by the email domain.
Configure an email address on your domain, replace me#mydomain.com with your newly created email address on your domain andid#hotmailOrgmail.com with your Hotmail/Gmail id in the following script.
Also replace Your Name with your name in the following script and test it on your server:
<?php
$myName = "Your Name";
$myEmailAddressonDomain = "me#mydomain.com";
$myPreferredEmailAddresson = "id#hotmailOrgmail.com";
$mail = $_POST['email_field'];
$clientName = $_POST['name_field'];
$subject = $_POST['subject_field'];
$text = $_POST['message_field'];
$headers = 'From: "$name" <$yourEmailAddressonDomain>'.PHP_EOL.'Reply-To: '.$_POST['mail'].PHP_EOL;
$to = '"$yourname" <$myPreferredEmailAddresson>';
$message = $text.PHP_EOL.PHP_EOL."---".PHP_EOL."From: ".$name." <".$mail.">";
/* Server-side form validations */
$err = "Error with ";
if (!checkLen($name)) {
$err.='Name';
} else if (!checkLen($mail) && !checkEmail($mail)) {
$err.='Email';
} else if (!checkLen($subject)) {
$err.='Subject';
} else if (!checkLen($text)) {
$err.='Message';
}
if (strlen($err)>11) {
echo $err.' field';
exit;
}
/* end validations */
elseif (mail($to, $subject,$message, $headers)) {
echo "<span style='color: #336600'>Your message has been sent.</span>";
} else {
echo "An error occurred, please try again.";
}
function checkLen($str,$len=1)
{
return isset($str) && mb_strlen(strip_tags($str),"utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[#][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
?>
The email will land on your Hotmail/Gmail inbox (or any non-spam) folder via your domain's email address.
Note: Clicking Reply in the received email would show you the client's email address (as we have set in Reply-To header above)
Make appropriate changes and you are good to go.
as you are operating VPS, you may consider setting up DKIM and SPF on your server, they are used by mail services like Gmail to classify your server as a legitimate server.

Categories