Jump to content

Sbscribe form


wisemonk
Go to solution Solved by Frank_b,

Recommended Posts

I have this code I have been trying ot use but it doesnt sent an email to my account when someone enters there email address into it and hots the submit button 

 

this is the php side of it

<?php
if ( isset( $_POST['newsletter_submit'] ) ) {
	// Initialize error array
	$newsletter_errors = array();

	// Check email input field
	if ( trim( $_POST['newsletter_email'] ) === '' )
		$newsletter_errors[] = 'Email address is required';
	elseif ( !preg_match( "/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,4}$/i", trim( $_POST['newsletter_email'] ) ) )
		$newsletter_errors[] = 'Email address is not valid'; 
	else
		$newsletter_email = trim( $_POST['newsletter_email'] );
	
	// Send email if no input errors
	if ( empty( $newsletter_errors ) ) {
		$email_to = "news@upperhuntercomputers.com"; // Change to your own email address
		$subject = "Newsletter Subscription";
		$body = "Subscriber details: " . $newsletter_email . "\r\n";
		$headers = "Newsletter Subscription <" . $email_to . ">\r\nReply-To: " . $newsletter_email . "\r\n";
		mail( $email_to, $subject, $body, $headers );
		echo 'Thank you for subscribing!';
	} else {
		echo 'Please go back and correct the following errors:<br />';
		foreach ( $newsletter_errors as $error ) {
			echo $error . '<br />';
		}
	}
}
?>

and this is the html side of it

<!-- Newsletter form -->
			<div class="newsletter">
				<form action="subscribe.php" method="post" id="newsletter-form">
					<p class="form-field">
						<label for="newsletter_email" class="visually-hidden">Your email address</label>
						<i class="icon ion-paper-airplane" aria-hidden="true"></i>
						<input type="text" name="newsletter_email" id="newsletter_email" value="" placeholder="Your email address" />
					</p>
					<p class="form-submit">
						<input type="submit" name="newsletter_submit" id="newsletter_submit" value="Get Notified" />
					</p>
				</form>
			</div>

		</div>

cant figure out why its not working properly

Link to comment
Share on other sites

At first try to use the mail function standalone like this

mail('myself@gmail.com','testmail','Hi did you receive this mail?');


Check if you receive the testmail. Don't forget to look into the spam map also.

 

If you do not receive the email then the email() function might be disabled in the php configuration file or the outgoing email server has not been properly set.

 

Please tell us more about the machine where you run you scripts from. (Windows or Linux, home computer or provider ?)

Link to comment
Share on other sites

hey there it didnt work with the the simple form either dont receive any emails and ther not in the junk folder so not sure whats going on there or where to really look to receive emails from the web site as its all hosted on the same location as well 

 

if it helps this is the web site im trying to implement the subscribe form on www.upperhuntercomputers.com

Edited by wisemonk
Link to comment
Share on other sites

  • Solution

Hi,

 

My advise is to contact the supportdesk of your provider

 

or

 

to use PHPMailer to send your emails by a SMTP server. For example you can use a SMTP server from godaddy.com or one from your internet-connection provider or gmail.com for example.

 

You can find the original PHPMailer repository at https://github.com/PHPMailer/PHPMailer

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.