Lastbreath Posted November 6, 2013 Share Posted November 6, 2013 Hi im new to webdesigning, so ive made this portfolio http://vasilstojanoski.atspace.eu, the issue is with the email form on the last tab, now if i make mail at the host cpanel i can send mails from the form, and if i dont make it doesnt send mails, also i get annoyed that whenever i test it with different mail, when i check the mail it always says its sended from the mail that i have on the host not the one that i type in the input. i found this 2 codes and little messed arround, they both work at localhost both work at the website only the first doesnt work if i use $mailheader = "From: $email \r\n"; <?php $to = 'vasilstojanoski24@gmail.com'; $from = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $message = " $message \r \n "; $mailheader = "From: $email \r\n"; if ($_POST['submit']) { if (mail ($to, $subject, $message, $mailheader,$headers)) { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } } ?> <?php // Used for later to determine result $success = $error = false; if (!empty($_POST)) { // Object syntax looks better and is easier to use than arrays to me $post = new stdClass; // Usually there would be much more validation and filtering, but this // will work for now. foreach ($_POST as $key => $val) $post->$key = trim(strip_tags($_POST[$key])); // Check for blank fields if (empty($post->name) OR empty($post->email) OR empty($post->subject) OR empty($post->message)) $error = true; else { // Load the SwiftMailer files require_once'swift/swift_required.php'; // Mail $transport = Swift_MailTransport::newInstance(); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance() ->setSubject($post->subject) // Message subject ->setTo(array('vasil.stojanoski24@gmail.com' => 'Vasil Stojanoski Portfolio')) // Array of people to send to ->setFrom(array($post->email => $post->name)) // From: ->setBody($post->message, 'text/html'); // Send the email, and show user message $result = $mailer->send($message); header('Location: index.php'); } } ?> so can u tell me wich one is better to use, the first wich is simple, or second that uses swiftmailer, and how to fix that instead of getting from: domain@mail to get the mail that is used in the input filed? Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/ Share on other sites More sharing options...
jazzman1 Posted November 6, 2013 Share Posted November 6, 2013 Use swiftMailer. and how to fix that instead of getting from: domain@mail to get the mail that is used in the input filed? This line of code is correct: ->setFrom(array($post->email => $post->name)) // From: Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457278 Share on other sites More sharing options...
Lastbreath Posted November 6, 2013 Author Share Posted November 6, 2013 Use swiftMailer. This line of code is correct: ->setFrom(array($post->email => $post->name)) // From: Tnx for the reply. Yes m8 i also think the code is correct, but it doesnt work mean it doesnt put out test@yahoo.com and i dont know why, everytime i put different mail and open it in my gmail it says it comes from the mail that ive made on my host page test@atspace.com. ill try contact the host support coz i think something doesnt work properly from their side, coz a friend of mine uses simular swiftmailer code he is on another host, he didnt had to make mail on the host so the option to send mails to work. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457283 Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 Does your provider provide you a smtp relay hosting? What's the name of your hosting provider? Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457293 Share on other sites More sharing options...
Lastbreath Posted November 7, 2013 Author Share Posted November 7, 2013 (edited) http://www.atspace.com/web-hosting i use the basic hosting. Edited November 7, 2013 by Lastbreath Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457363 Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 (edited) Try to run next code and tell me what you get: <?php $from = "From: jazz <jazzman@jazzman.com>"; $to = "you@yourdomain.com"; // your gmail account $subject = "Hi! "; $body = "TEST"; if(mail($to,$subject,$body,$from)) echo "MAIL - OK"; else echo "MAIL FAILED"; Edited November 7, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457365 Share on other sites More sharing options...
Lastbreath Posted November 7, 2013 Author Share Posted November 7, 2013 Try to run next code and tell me what you get: <?php $from = "From: jazz <jazzman@jazzman.com>"; $to = "you@yourdomain.com"; // your gmail account $subject = "Hi! "; $body = "TEST"; if(mail($to,$subject,$body,$from)) echo "MAIL - OK"; else echo "MAIL FAILED"; Tryed still same From: mail@vasilstojanoskiatspace.eu not jazzman@jazzman.com, if i remove that mail at the host, message fails. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457391 Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 (edited) It has nothing to do because you don't have a own domain name registered by you! Perhaps, you're using some free shared hosting plan, right? Edited November 7, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457427 Share on other sites More sharing options...
Lastbreath Posted November 7, 2013 Author Share Posted November 7, 2013 It has nothing to do because you don't have a own domain name registered by you! Perhaps, you're using some free shared hosting plan, right? i just bought a domain and setting it atm, gonna try and see what will change, im on http://www.atspace.com/web-hosting using the basic hosting plan. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457428 Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 (edited) Why are you using their domain name then -> http://vasilstojanoski.atspace.eu This domain is hosting by - www.runhosting.com Edited November 7, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457429 Share on other sites More sharing options...
Lastbreath Posted November 7, 2013 Author Share Posted November 7, 2013 Why are you using their domain name then -> http://vasilstojanoski.atspace.eu This domain is hosting by - www.runhosting.com It just a subdomain that i entered for the moment, i didnt had money on my paypal, i got domain now connected with the host, just w8ting to say its ok and ill try how will the mail works. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457431 Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 Try with the code that I provided you above, then switch to swiftmaler, it should be OK. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457434 Share on other sites More sharing options...
Lastbreath Posted November 7, 2013 Author Share Posted November 7, 2013 Try with the code that I provided you above, then switch to swiftmaler, it should be OK. Hmm ive tryed and still the same, then i checked faq it says : Our servers require SMTP authentication, which in plain English means you will have to use any of your e-mail accounts, created within the E-mail Manager -> E-mail Accounts section from your control panel. with other words, i need to use headers, or there is another way? Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457453 Share on other sites More sharing options...
jazzman1 Posted November 7, 2013 Share Posted November 7, 2013 What's your domain name now? Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457462 Share on other sites More sharing options...
Lastbreath Posted November 7, 2013 Author Share Posted November 7, 2013 What's your domain name now? vasilstojanoski.com Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457464 Share on other sites More sharing options...
Lastbreath Posted November 8, 2013 Author Share Posted November 8, 2013 ->setReplyTo(array($post->email => $post->name)) worked but from: still stands the email host acc. i just get 1 like more on gmail/yahoo that says the name and the email that were inputed in the inputs. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457468 Share on other sites More sharing options...
jazzman1 Posted November 8, 2013 Share Posted November 8, 2013 Vasile, send me an email at tuparov86@gmail.com to check the mail's header. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457471 Share on other sites More sharing options...
jazzman1 Posted November 8, 2013 Share Posted November 8, 2013 Is there a way to control what ports are open or closed for your hosting plan? Port 25 is open, close it, you don't need to be open unless you have some application that is setup to send email notices from the hosting server. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457513 Share on other sites More sharing options...
Lastbreath Posted November 8, 2013 Author Share Posted November 8, 2013 Is there a way to control what ports are open or closed for your hosting plan? Port 25 is open, close it, you don't need to be open unless you have some application that is setup to send email notices from the hosting server. trying to find , but as i see there isnt a way to get to port 25 smtp options. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457569 Share on other sites More sharing options...
jazzman1 Posted November 8, 2013 Share Posted November 8, 2013 Then mail them, because I'm going to divine what could to cause the problem. I did not see anything wrong in the headers. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457575 Share on other sites More sharing options...
Lastbreath Posted November 8, 2013 Author Share Posted November 8, 2013 Sorry i dont understand , mail them? i must have email on the host so the form is able to send mails. and the wrong in the headers is that From: its always the host mail account, not the one entered in the input, that now goes in the reply to: , its kinda stupid im searching a way that not to be shown and cant find. this is the code atm, and setFrom is not fetching and sending what setReplyTo is. im gonna try some other script instead of swiftmailer tommorrow, or maybe some other host ill see $message = Swift_Message::newInstance() ->setSubject($post->subject) // Message subject ->setTo(array('vasil.stojanoski24@gmail.com' => 'Vasil Stojanoski Portfolio')) // Array of people to send to ->setFrom(array($post->email => $post->name)) // From: ->setReplyTo(array($post->email => $post->name)) ->setBody($post->message, 'text/html'); Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457588 Share on other sites More sharing options...
jazzman1 Posted November 8, 2013 Share Posted November 8, 2013 Sorry i dont understand , mail them? Just ask, phone or email them (your current hosting provider) why that happened and how to solve this issue? You can switch of course your hosting provider to GoDaddy or HostGator. I don't have any problems with them many years. Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457597 Share on other sites More sharing options...
Lastbreath Posted November 8, 2013 Author Share Posted November 8, 2013 Just ask, phone or email them (your current hosting provider) why that happened and how to solve this issue? You can switch of course your hosting provider to GoDaddy or HostGator. I don't have any problems with them many years. Ill do that, tnx for the help Quote Link to comment https://forums.phpfreaks.com/topic/283652-email-form-help/#findComment-1457615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.